CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2008
    Posts
    4

    charset problem?

    Hey!

    http://www.roscripts.com/Ajax_autosu...abase-154.html

    I'm using this neat script for searching on my website.. but the thing is i have saved sentences with norwegian special charachters to my db, and when these are printed with this script the æ ø å's shows up like "?" instead. I am using charset=iso-8859-1 in the <head> tag
    and charset=iso-8859-1 in the <script> tag


    all other special characters show up as they should, its ONLY those who goes thru the search script that doesnt show up as they should.

    I really hope someone understands my problem and could come with some input since i really want to use this on my site

  2. #2
    Join Date
    Feb 2007
    Location
    Craiova, Romania
    Posts
    326

    Re: charset problem?

    Those characters are part of the UTF-8 charset.
    PHP is known to have some problems with multibyte characters, since 1 char in PHP is represented on 1 byte.

    The solution is fairly simple: change the header and content type encoding to utf-8:
    Code:
    header('Content-Type: text/html; charset=utf-8');
    ...
    and later:
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    ...
    Hope this helps.

  3. #3
    Join Date
    Jan 2008
    Posts
    4

    Re: charset problem?

    Thanks for the reply!
    When I did what you told me, the search part worked! I could search after special characters, and they showed up .. but all other special characters that is in my index.php suddenly went to "?".. how come? :S since they showed up when i used the iso88-59-1, they should show when i use the uft-8 too? i dont really understand why this happens?

  4. #4
    Join Date
    Feb 2007
    Location
    Craiova, Romania
    Posts
    326

    Re: charset problem?

    Maybe you added the header encoding too late and the browser assumed a default encoding.

    Make sure that both header and content-type encodings apply to index.php.

  5. #5
    Join Date
    Jan 2008
    Posts
    4

    Re: charset problem?

    ok. it works now i just had to close the meta tag! with a "/>".

    Thanks alot!

    btw..
    all data that has been written in my form and sent to my database while i used the iso 8xxx charset wont come turn up as special characters when i use utf-8 ?

  6. #6
    Join Date
    Feb 2007
    Location
    Craiova, Romania
    Posts
    326

    Re: charset problem?

    Depends on how it was saved in the db.
    Anyway, if it turns out that the data wasn't saved OK, then modify all your forms and add this extra attribute, to make sure they will post utf-8 encoded data:
    Code:
    <form ... accept-charset="utf-8" ... >
       ...
    </form>

  7. #7
    Join Date
    Jan 2008
    Posts
    4

    Re: charset problem?

    ok. seems like it wasnt saved as utf-8. I'll add that code to my forms just in case then thanks alot again, and happy new year!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured