Character Encoding in PHP
Posted by JimL (JimL), 29 August 2006This may seem a basic question, and I do ramble on a bit, but hopefully if you follow my logic you will understand where my confusion lies!
When a webserver serves a standard file, the encoding that the receiving browser needs to know is the encoding of the file itself (i.e. the encoding when the file was created). For example if I create a HTML file in notepad, I can choose to save that file using UTF-8 encoding. Therefore the browser, in order to successfully parse that file needs to know that the file is encoded in UTF-8.
However, in PHP.ini you can set "default_charset" to anything you like. Therefore if my file is encoded in UTF-8, but my "default_charset" is ISO-8859-1 am I likely to run into problems?
Second question: what encoding will PHP send if I completely generate the page dynamically (e.g. from the result of a MySQL query).
Posted by admin (Graham Ellis), 30 August 2006PHP's header function lets you set a specific encoding if you need to do so, and htmlentities lets you encode your string, telling it (in recent versions) which encoding to use.
I'm not sure if this answers the question / helps - I tend to use htmlentities when I need to. I think that what comes back from the MySQL database is simply an echo of what was put in (your second question) apart from the extra "addslashes" that you'll have used to insert blobs. It's just a holder and the encodeing of the insert followed by the decodong of the select should have balanced out. Treat your data as you would have treated the data prior to insertion.
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho