SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2007
    Location
    Toronto
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Special Characters pulled from MySql Database

    Hey guys,

    I have a website that pulls info from a database. In the database, the data (which is user-entered) is often entered as curly quotes or long dashes. The result is, the database holds them as †or other similar gobbledy-gook.

    When PHP displays this data on the web page, it still looks like funny characters. So, on the web page, something like "Farmer's Market" will instead appear as "Farmer’s Market".

    This site was recently converted from ASP to PHP, and it was working fine in ASP, displaying everything properly, I believe using a particular function to convert the characters.

    It seems that there should be a simple built-in function to do this in PHP, but I can't seem to find the right one on PHP.net.

    Any help is appreciated.

    Thanks,
    Louis

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make sure your page is served as utf-8, make sure your db is utf-8.

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2007
    Location
    Toronto
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've tried inserting:

    Code:
    header('content-type: text/html; charset: utf-8');
    at the top of the PHP document.

    I've tried inserting:

    Code:
    mysql_query('SET NAMES utf8');
    after mysql_connect.

    And my database lists each field's "collation" as "utf8_general_ci". And my HTML page has its content-type meta tag set to "text/html; charset=UTF-8".

    I also tried displaying the data using the utf8_decode() and utf8_encode() function. While they do give different results, they still display messed up characters, just different characters in each instance.

    Thanks,
    Louis

  4. #4
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It seems that there should be a simple built-in function to do this in PHP
    Yet, the solution is not to use any built in functions, either when displaying data and then entering it.
    When data goes straight to database and straight from it, nothing bad can be occurred.
    I suspect you do some unnecessary data preparation.

  5. #5
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What happens if you enter this string in a form? What's stored in db? What's output to browser? What's in post var?
    Code:
    Iñtërnâtiônàlizætiøn

  6. #6
    SitePoint Zealot
    Join Date
    Aug 2007
    Location
    Toronto
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm going to have to rethink this issue, because I think the problem is that the information is being manually entered into PHPMyAdmin from emails that are automatically sent. Unfortunately, the site is not inputting user info directly into the db, but instead the info is being emailed, then a moderator copies and pastes the info into fields in PHPMyAdmin.

    I just assumed there was some way to pull those funny characters out and convert them in PHP. I'll have to retest this once the form is set up to put the info directly into the DB.

    Thanks for the help.

    Louis


Tags for this Thread

Bookmarks

Posting Permissions

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