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?
use mysql_real_escape_string() function.
for more details look the site given below.
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?
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.
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?
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.