PDA

View Full Version : accented characters in MySQL database



stevenvh
07-08-2009, 11:31 AM
Hi,
I'm setting up a database with a text field which has to accept accented characters. Collation ascii_bin was a bad choice (obviously), so I changed it to utf8_bin.
This seemed to work; the text appears correctly when I enter it using PHPMyAdmin. But when I read the record and try to replace the accented character with the "&-something" to place in HTML, PHP doesn't seem to find it. This is what I tried:

$title = str_replace("é", "é", $title);

$title remains unchanged.
Any ideas what I'm doing wrong?

Related question: is there an elegant way to replace all accented characters in one operation, i.e. "é" by "&eacute", "à" by "agrave", etc.?

TIA
Steven

cubbieco
07-08-2009, 05:00 PM
I'm no expert and I don't have anything I can test this with, but try using htmlentities().

stevenvh
07-09-2009, 12:12 AM
Thanks cubbieco, htmlentities() does the trick. I guess there must have been a difference between the "é" in the record and the one in my php code. Probably to do with UTF8.
Thanks again.
Steven