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?
Are you using htmlentities() to output any of this text? If so, be sure to use the optional 3rd parameter, e.g.:
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().
echo htmlentities($text, ENT_QUOTES, 'UTF-8');
"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
How to Ask Questions the Smart Way
(not affiliated with this site, but well worth reading)
Also, check if the php script has included
And the php file is saved in utf-8 format.
header('Content-type: text/html; charset=utf-8');
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?
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread