www.webdeveloper.com
Results 1 to 4 of 4

Thread: Basic UTF-8 error with PHP?

  1. #1
    Join Date
    Mar 2007
    Posts
    23

    Basic UTF-8 error with PHP?

    I'm developing a site that uses some php includes, but with no mysql and I am missing something.

    The pages in question are in French and English and there will be more languages later so I've set it to UTF-8.

    Using .php, When I put in characters such as etc. in the html, they show as little question marks despite the fact that I'm sending a UTF-8 content-type header and have set the relevant metatag to UTF-8.

    However, if I copy the source of the page and paste it into a non-php XHTML document, then revert the question marks back to in the source with , etc. that page shows the characters fine.

    My conclusion is that the problem lies with PHP character encoding. Can anybody tell me what I need to add to fix it, both by php.ini and PHP command in the file?

    Thanks

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,145
    Are you using htmlentities() to output any of this text? If so, be sure to use the optional 3rd parameter, e.g.:
    PHP Code:
    echo htmlentities($textENT_QUOTES'UTF-8'); 
    Also, make sure whatever editor you are using for your PHP files is saving it as UTF-8 with no BOM (byte order mark). If it is including the BOM, that will prevent your header() function from working, as output will have already been sent to the browser (the BOM) before the call to header().
    "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

  3. #3
    Join Date
    Feb 2011
    Posts
    231
    Also, check if the php script has included
    PHP Code:
    header('Content-type: text/html; charset=utf-8'); 
    And the php file is saved in utf-8 format.

  4. #4
    Join Date
    Mar 2007
    Posts
    23
    Hi there,

    Thanks for the reply. It's not really an htmlentities thing in this case. My problem is that, as it stands with the utf-8 html headers in place all static content is rendered correctly if the content is in a static page. Take the same page and run it through the php engine and that content no longer renders correctly. The content in question is being served as an include in another page and I've read that PHP has some sort of bug to do with the Byte Order Mark on a UTF-8 include. Is that my problem here?

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