cutcopypaste — 2010-11-28T23:20:29-05:00 — #1
I have my mysql database set to utf-8, but when I put in the ”angled quotes” and apostrophes generally copied from other content, it just ends up being outputted as an unrecognized character (black diamond with a ?) by the php (it looks fine in the db itself). Is there some change I can make to the php.ini to make these show up properly?
Is there some sort of best practice set-up to try and get away from these problems?
kiran_dangol — 2010-11-29T00:19:30-05:00 — #2
use mysql_real_escape_string() function.
for more details look the site given below.
cutcopypaste — 2010-12-03T21:10:40-05:00 — #3
Hi! Unfortunately that doesn't help me here. It removes all the line breaks from what's stored in the database, but it doesn't help with the funky characters.. they still show up as unrecognized.
I can run utf8_encode function on the data and it will show up properly actually.
But is there some way I can set things up to negate the need to do this.. like set php for the whole site to run in utf-8 somehow?
thruska — 2010-12-04T13:31:09-05:00 — #4
If you want to set UTF-8, you should use a combination of a PHP header call:
header("Content-Type: text/html; charset=utf-8");
And a meta http-equiv tag:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
In the 'head' of your HTML. Browsers will pick either one or both up and display the page and submit content as UTF-8 to the server.
spacephoenix — 2010-12-04T14:39:46-05:00 — #5
When you say:
it looks fine in the db itself
How are you viewing the records (via phpMyAdmin, MySQL console, etc)?
When your connecting to MySQL from php are you specifiying what character set the connection is to use?
cutcopypaste — 2010-12-05T15:16:04-05:00 — #6
Hm.. I tried both of those things and it still shows up unrecognized without the actual utf8_encode function applied to the echo statement. That seems strange..
I was looking at the db both in phpmyadmin and Sequel pro (it's on localhost right now) My db wasn't originally in utf-8, but I ran a collation command to convert it (it was having the same problem originally), and now it seems to think it's utf-8 so that's good. I've also tried re-adding the data (pasting it into textedit and then back). The text was originally just copy/pasted from allmusic or somwhere like that.