Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Character Encoding in PHP

Posted by JimL (JimL), 29 August 2006
This 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).

Cheers,  Jim

Posted by admin (Graham Ellis), 30 August 2006
PHP'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.

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho