louis_lazaris — 2010-03-14T04:52:20-04:00 — #1
I have a website that pulls info from a database. In the database, the data (which is user-entered) is often entered as curly quotes or long dashes. The result is, the database holds them as â€ or other similar gobbledy-gook.
When PHP displays this data on the web page, it still looks like funny characters. So, on the web page, something like "Farmer's Market" will instead appear as "Farmerâ€™s Market".
This site was recently converted from ASP to PHP, and it was working fine in ASP, displaying everything properly, I believe using a particular function to convert the characters.
It seems that there should be a simple built-in function to do this in PHP, but I can't seem to find the right one on PHP.net.
Any help is appreciated.
hash — 2010-03-14T05:05:48-04:00 — #2
Make sure your page is served as utf-8, make sure your db is utf-8.
louis_lazaris — 2010-03-14T05:29:13-04:00 — #3
I've tried inserting:
header('content-type: text/html; charset: utf-8');
at the top of the PHP document.
I've tried inserting:
mysql_query('SET NAMES utf8');
And my database lists each field's "collation" as "utf8_general_ci". And my HTML page has its content-type meta tag set to "text/html; charset=UTF-8".
I also tried displaying the data using the utf8_decode() and utf8_encode() function. While they do give different results, they still display messed up characters, just different characters in each instance.
system — 2010-03-14T05:42:54-04:00 — #4
It seems that there should be a simple built-in function to do this in PHP
Yet, the solution is not to use any built in functions, either when displaying data and then entering it.
When data goes straight to database and straight from it, nothing bad can be occurred.
I suspect you do some unnecessary data preparation.
hash — 2010-03-14T05:57:31-04:00 — #5
What happens if you enter this string in a form? What's stored in db? What's output to browser? What's in post var?
louis_lazaris — 2010-03-14T06:16:15-04:00 — #6
I'm going to have to rethink this issue, because I think the problem is that the information is being manually entered into PHPMyAdmin from emails that are automatically sent. Unfortunately, the site is not inputting user info directly into the db, but instead the info is being emailed, then a moderator copies and pastes the info into fields in PHPMyAdmin.
I just assumed there was some way to pull those funny characters out and convert them in PHP. I'll have to retest this once the form is set up to put the info directly into the DB.
Thanks for the help.