12 Replies Latest reply on Mar 9, 2007 9:00 AM by Newsgroup_User

    convert utf-8 to iso-8859-1

    Level 7
      Hello,
      sorry for my very bad english

      i use httpxmlrequest to answer a database and show resultin a div
      the string means utf-8 encoded by my javascript fonction and, of course,
      no result are found in the database.
      How can i convert the string to iso-8859-1 before request the database ?

      Thank if you have an idea

      JiBé (France)
        • 1. Re: convert utf-8 to iso-8859-1
          BKBK Adobe Community Professional & MVP
          What happens when you put

          <cfscript>
          SetEncoding("url", "iso-8859-1");
          </cfscript>
          <cfprocessingdirective pageencoding="iso-8859-1">

          at the top of the Coldfusion page?


          • 2. Re: convert utf-8 to iso-8859-1
            Level 7

            I do that in the application.cfm page
            I just have this problem with httpxmlrequest
            So i want to convert my string before use it in the SQL

            JiBé
            >
            > <cfscript>
            > SetEncoding("url", "iso-8859-1");
            > </cfscript>
            > <cfprocessingdirective pageencoding="iso-8859-1">
            >
            > at the top of the Coldfusion page?
            >
            >
            >
            • 3. Re: convert utf-8 to iso-8859-1
              Level 7
              Jib wrote:
              > How can i convert the string to iso-8859-1 before request the database ?

              well you might not be able to as iso-8859-1 is a subset of unicode. what
              languages are you dealing with? are you sure they will fit into iso-8859-1? i
              guess maybe have a look at this:
              http://www.phillipholmes.com/?p=46
              • 4. Re: convert utf-8 to iso-8859-1
                Level 7
                PaulH **AdobeCommunityExpert** a écrit :
                > Jib wrote:
                >> How can i convert the string to iso-8859-1 before request the database ?

                Maybe it is more simple with an example :
                http://habitat-developpement.tm.p15.siteinternet.com/test/
                If you seach energie it works...
                If oyu search énergie there is no result because it search "énergie"...

                Jibé
                > well you might not be able to as iso-8859-1 is a subset of unicode. what
                > languages are you dealing with? are you sure they will fit into
                > iso-8859-1? i guess maybe have a look at this:
                > http://www.phillipholmes.com/?p=46
                • 5. Re: convert utf-8 to iso-8859-1
                  BKBK Adobe Community Professional & MVP
                  Couldn't you just do everything in utf-8?

                  • 6. Re: convert utf-8 to iso-8859-1
                    Level 7
                    Jibé wrote:
                    > Maybe it is more simple with an example :
                    > http://habitat-developpement.tm.p15.siteinternet.com/test/

                    show the code for that. it seems your encoding isn't the same back-to-front. is
                    it getting to the db ok? what db? what encoding in the db?
                    • 7. Re: convert utf-8 to iso-8859-1
                      Level 7
                      PaulH **AdobeCommunityExpert** a écrit :
                      I work with a MS SQL server database encoding in iso-8859-1
                      The code :
                      <cfif len(form.id) GT 2>
                      <cfquery name="l_fichier" datasource="#bdd#">
                      select *
                      from fichier
                      where titre like '%#form.id#%'
                      or contenu like '%#form.id#%'
                      order by rubrique
                      </cfquery>
                      <cfelse>
                      <cfset l_fichier.recordcount = 0>
                      </cfif>

                      <cfoutput>
                      <b> Résultat de votre recherche #form.id#</b>
                      <div id="trans">
                      <cfif l_fichier.recordcount EQ 0>
                      <div id="resultat">Aucun fichier ne correspond à votre demande</div>
                      <cfelse>
                      <div id="x_contenu">
                      <cfloop query="l_fichier">
                      #lsdateformat(date_modif,'dd/mm/yyy')# - #titre#<br/>
                      </cfloop>
                      </div>
                      </cfif>
                      </div>
                      </cfoutput>

                      JiBé
                      >
                      > show the code for that. it seems your encoding isn't the same
                      > back-to-front. is it getting to the db ok? what db? what encoding in the
                      > db?
                      • 8. Re: convert utf-8 to iso-8859-1
                        Level 7
                        BKBK a écrit :
                        > Couldn't you just do everything in utf-8?
                        >
                        >
                        I'm not the owner of the database... I just use it.

                        JiBé
                        • 9. Re: convert utf-8 to iso-8859-1
                          Level 7
                          Jibé wrote:
                          > PaulH **AdobeCommunityExpert** a écrit :
                          > I work with a MS SQL server database encoding in iso-8859-1

                          data stored in plain text,char,varchar datatypes (ie not "N")? using the ODBC or
                          JDBC (it would be listed as ms sql server in the db drivers list) driver?

                          > The code :

                          you're not following good i18n practices. while my preference is for unicode
                          ("just use unicode" has been my motto for years), if you're really only ever
                          going to use french & never need the euro symbol then i guess iso-8859-1
                          (latin-1) is fine.

                          add to top of all your cf pages:
                          <cfprocessingdirective pageencoding="iso-8859-1">

                          in your application.cfm (or it's equivalent) add:
                          <cfset setEncoding("form","iso-8859-1")>
                          <cfset setEncoding("url","iso-8859-1")>
                          <cfcontent type="text/html; charset=iso-8859-1">

                          if you think you might need other languages, including the euro symbol, then you
                          should consider unicode. change your text columsn to "N" type (nText, nChar,
                          nVarChar) & swap the latin-1 encodings in the tags above to utf-8.
                          • 10. Re: convert utf-8 to iso-8859-1
                            Level 7
                            Jibé wrote:
                            > PaulH **AdobeCommunityExpert** a écrit :
                            > I work with a MS SQL server database encoding in iso-8859-1

                            data stored in plain text,char,varchar datatypes (ie not "N")? using the ODBC or
                            JDBC (it would be listed as ms sql server in the db drivers list) driver?

                            > The code :

                            you're not following good i18n practices. while my preference is for unicode
                            ("just use unicode" has been my motto for years), if you're really only ever
                            going to use french & never need the euro symbol then i guess iso-8859-1
                            (latin-1) is fine.

                            add to top of all your cf pages:
                            <cfprocessingdirective pageencoding="iso-8859-1">

                            in your application.cfm (or it's equivalent) add:
                            <cfset setEncoding("form","iso-8859-1")>
                            <cfset setEncoding("url","iso-8859-1")>
                            <cfcontent type="text/html; charset=iso-8859-1">

                            if you think you might need other languages, including the euro symbol, then you
                            should consider unicode. change your text columsn to "N" type (nText, nChar,
                            nVarChar) & swap the latin-1 encodings in the tags above to utf-8.
                            • 11. Re: convert utf-8 to iso-8859-1
                              Level 7
                              PaulH **AdobeCommunityExpert** a écrit :
                              > Jibé wrote:
                              >> PaulH **AdobeCommunityExpert** a écrit :
                              >> I work with a MS SQL server database encoding in iso-8859-1
                              >
                              > data stored in plain text,char,varchar datatypes (ie not "N")?
                              datatype of "titre" is varchar(250) and "contenu" is text
                              using the
                              > ODBC or JDBC (it would be listed as ms sql server in the db drivers
                              > list) driver?
                              I think it's jdbc driver (case of my test computer)


                              >
                              >> The code :
                              >
                              > you're not following good i18n practices. while my preference is for
                              > unicode ("just use unicode" has been my motto for years), if you're
                              > really only ever going to use french & never need the euro symbol then i
                              > guess iso-8859-1 (latin-1) is fine.

                              Here is a part of the content of my application.cfm
                              <cfprocessingdirective pageencoding="iso-8859-1">
                              <cfcontent type="text/html; charset=iso-8859-1">
                              <cfset setEncoding("URL", "iso-8859-1")>
                              <cfset setEncoding("Form", "iso-8859-1")>

                              >
                              > if you think you might need other languages, including the euro symbol,
                              > then you should consider unicode. change your text columsn to "N" type
                              > (nText, nChar, nVarChar) & swap the latin-1 encodings in the tags above
                              > to utf-8.
                              I'm going to test that....

                              JiBé
                              • 12. Re: convert utf-8 to iso-8859-1
                                Level 7
                                OK, if i add
                                <cfset setEncoding("Form", "utf-8")> at the top of my
                                x_fichier_cherche.cfm it works fine

                                Thank's a lot for your help.

                                JiBé