SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2009
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    unrecognized characters/encoding

    I have my mysql database set to utf-8, but when I put in the ”angled quotes” and apostrophes generally copied from other content, it just ends up being outputted as an unrecognized character (black diamond with a ?) by the php (it looks fine in the db itself). Is there some change I can make to the php.ini to make these show up properly?
    Is there some sort of best practice set-up to try and get away from these problems?

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2010
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello cutcopypaste,
    use mysql_real_escape_string() function.
    for more details look the site given below.
    http://php.net/manual/en/function.my...ape-string.php

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2009
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi! Unfortunately that doesn't help me here. It removes all the line breaks from what's stored in the database, but it doesn't help with the funky characters.. they still show up as unrecognized.
    I can run utf8_encode function on the data and it will show up properly actually.
    But is there some way I can set things up to negate the need to do this.. like set php for the whole site to run in utf-8 somehow?

  4. #4
    SitePoint Zealot
    Join Date
    Jun 2010
    Location
    Arizona
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to set UTF-8, you should use a combination of a PHP header call:

    header("Content-Type: text/html; charset=utf-8");

    And a meta http-equiv tag:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    In the 'head' of your HTML. Browsers will pick either one or both up and display the page and submit content as UTF-8 to the server.
    Thomas Hruska

    Single Sign-On Server/Client - The PHP login system that rocks.

  5. #5
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    4,904
    Mentioned
    93 Post(s)
    Tagged
    0 Thread(s)
    When you say:

    it looks fine in the db itself
    How are you viewing the records (via phpMyAdmin, MySQL console, etc)?

    When your connecting to MySQL from php are you specifiying what character set the connection is to use?
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  6. #6
    SitePoint Zealot
    Join Date
    Feb 2009
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by thruska View Post
    If you want to set UTF-8, you should use a combination of a PHP header call:

    header("Content-Type: text/html; charset=utf-8");

    And a meta http-equiv tag:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    In the 'head' of your HTML. Browsers will pick either one or both up and display the page and submit content as UTF-8 to the server.
    Hm.. I tried both of those things and it still shows up unrecognized without the actual utf8_encode function applied to the echo statement. That seems strange..
    I was looking at the db both in phpmyadmin and Sequel pro (it's on localhost right now) My db wasn't originally in utf-8, but I ran a collation command to convert it (it was having the same problem originally), and now it seems to think it's utf-8 so that's good. I've also tried re-adding the data (pasting it into textedit and then back). The text was originally just copy/pasted from allmusic or somwhere like that.


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
  •