www.webdeveloper.com
Results 1 to 6 of 6

Thread: UTF8 comparing with MySQL

  1. #1
    Join Date
    Dec 2009
    Posts
    3

    UTF8 comparing with MySQL

    Hi Folks,

    I have a database where the fields are stored in UTF8 and utf_general_ci. I'm pulling the data from the database and I then want to see if a pulled value is in a fixed array which I've coded into php (array("home","▄ber
    uns","strona głˇwna")).

    For some reason this doesn't seem to work. I've tried setting the Internal/External/Output character encodings and played with other settings, including utf8_en/decoding it as well. Even though in text, the value from MySQL reads "strona głˇwna" (which I believe means Home page in Polish) it doesn't get found with in_array.

    Any help would be great.

    Thanks

    A

  2. #2
    Join Date
    Nov 2008
    Posts
    2,477
    Are you running a SET NAMES query before querying for the data?

    Code:
    SET NAMES 'utf8'
    Are you also making sure your IDE is saving the source code as utf-8?

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,175
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Dec 2009
    Posts
    3
    Hi,

    I am using SET NAMES so the data should be coming out as UTF8 but it won't compare with the array. I'm not sure if I need to set something in PHP to make my array get read as fully UTF8 - even if the characters themselves are UTF8?

    Thanks

    A

  5. #5
    Join Date
    Nov 2008
    Posts
    2,477
    If the array is hard coded, and your IDE is using UTF-8, then I can't see any reason why it wouldn't compare. I just ran a test and it worked fine for me. All I can think of is that your IDE is using something other than UTF-8.

  6. #6
    Join Date
    Dec 2009
    Posts
    3
    Thank you for that help!!! That fixed it. I'm using PSPad and had obviously not encoded the actual PHP file correctly! Simple but annoying as I've not really used international codings before.

    A

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles