char encoding
View PDF
by: Admin
Total views: 409
You have probably see a lot of web pages that have weird unreadable chars, or maybe just a lot of question marks instead of letters. That is what we call an encoding problem. Find out how to fix it.
Every web page has an encoding, depending on the characters that are used. This encoding (charset) can be specified in the page headers, or in a meta tag :
If you want to use php to set the charset of a page, you can use : header('Content-type: text/html; charset=utf-8'); , just remember to put this at the begining of the page, before sending any other output. If the charset is not set, the browser will choose the most appropriate encoding.
An important thing to remember is that all the text you fill in a form in a page, unless specified otherwise in the form tag, will be sent to the server encoded with the encoding of the page from which you submitted the form. So, if you send submit a form from a page with charset=iso-8859-2, and then try to display that text in a page with a different charset, you may see strange chars / question marks. With php, you could fix this using iconv(), to change the encoding of a text. The downside is you would have to know the original encoding of that text.
About the Author
Rating: Not yet rated