This is an encoding problem. Thus, it may be mistaken at different levels, but most likely the rows in your database are encoded by utf-8, and you represent them as iso-8859-1. Or vice versa.
The correct way to fix this problem is to get character sets. The simplest strategy since you are using PHP is to use iso-8859-1 throughout the application. To do this, you must ensure that:
- All PHP source files are saved as iso-8859-1 (Not to be confused with cp-1252).
- Your web server is configured to serve files with
charset=iso-8859-1 - Alternatively, you can override web server settings from a PHP document using
header . - Alternatively, you can insert a meta tag in HTML that points to the same thing, but this is not strictly necessary.
- You can also specify the
accept-charset attribute in your <form> elements. - Database tables are encoded as latin1
- Database connection between PHP and database is set to latin1
If you already have data in your database, you should know that it is probably already confused. If you are not already at the production stage, just wipe it all and start. Otherwise, you will have to do some data wiping.
A note on meta tags, since everyone misunderstands what it is:
When the web server serves the file (HTML document), it sends some information that is not displayed directly in the browser. This is called HTTP headers. One of these headers is the Content-Type header, which defines the file type (eg. text/html ), as well as the encoding (aka charset). Although most web servers send a Content-Type header with charset information, it is optional. If not, the browser will interpret any meta tags using http-equiv="Content-Type" . It is important to understand that the meta tag is only interpreted if the web server does not send the header. In practice, this means that it is used only if the page is saved to disk and then opened from there.
This page has a very good explanation of these things.
troelskn Nov 09 '08 at 0:52 2008-11-09 00:52
source share