Weird Symbols With PHP/MySQL

Associate
Joined
6 Feb 2003
Posts
1,105
Location
London
Ok im not sure which of php or mysql is to blame but in generated letters and stuff which grab things from the database - whenever you get a £ sign or something it either outputs a  sign before it - or if its on a webpage form then a funny diamond shaped thing with a questionmark in it. I can get rid of the obscure Â's with a str_replace but im not sure why they are even getting there in the first place? Encoding £ as £ doesnt solve it - and because I generate PDF's from the data it interprets that as being £ literally so its not a solution.

Anyone come across this weirdness? It seems to happen with the * character aswell. The thing is using PHPmyAdmin the Â's are not visible in the stored data so I dunno what its doing.
 
I can't remember the exact fix, but it is to do with which character encoding you are using, and possibly a mis-match between encoding used on the page, and the encoding used on your server (either in PHP itself, or in your DB if it is stored values)
 
Looks like the data stored in your DB is encoded as UTF-8, but being displayed as ISO-8859-1 or similar.

You need to standardise what encoding you're using to store data and what you're using to display it. What collation are you using for your DB fields, what encoding is the data entry form using, what encoding is the display page using etc. etc.

A quick fix, on your 'display' side, would be to modify the headers so that the page is sent as UTF-8 encoded:
Code:
header('Content-Type: text/html; charset=utf-8')
(assuming you're using text/html).

You can check to see if this is the problem by switching page-encoding in your browser on a problem page. In Firefox,
Code:
View>Character Encoding>Unicode(UTF-8)
 
Mister_Pister said:
the collation is set to sweedish :o
Yep, that's the default - MySQL is a Swedish company. AFAIK the collation you're using only comes into play when native MySQL string functions are being used i.e. the actual storage method is the same for all encodings and should be transparent when you're simply inserting and retrieving strings.
 
Back
Top Bottom