Page 1 of 1
funky character: ,â€
Posted: Sun Feb 15, 2009 12:38 pm
by jwerre
Why do all my commas and colons and such get replace with this: " ,†" when i import a text doc?
$myText = file_get_contents("my.txt");
Re: funky character: ,â€
Posted: Sun Feb 15, 2009 12:40 pm
by Weirdan
Because the text you're importing is encoded in UTF-8, and you're treating it as ascii (or latin-1).
Re: funky character: ,â€
Posted: Mon Feb 16, 2009 5:06 pm
by jwerre
I'm not sure if this is related but is there any reason why the first line would insert into my DB and not the second?
The Miami area was better known as Biscayne Bay Country in the early years of its growth. The few published accounts from that period describe the area as a wilderness that held much promise.
Pericles was a prominent and influential statesman, orator, and general of Athens during the city's Golden Age—specifically, the time between the Persian and Peloponnesian wars.
Code: Select all
echo mysql_query ("INSERT INTO tb_level (level, words) VALUES ('2', '$sentences[$i]')");
TABLE looks like this
id int(5) auto_increment
level int(2)
words longtext utf8_general_ci
Re: funky character: ,â€
Posted: Mon Feb 16, 2009 7:04 pm
by Weirdan
Unfortunately there are more places than mere table specification where encoding issues are coming into play. This is a simple 'recipe' that worked well for me over the years:
- Once database connection is set up (meaning right after mysql_connect() call), run 'set names utf8' query on it
- Make sure database tables/fields have 'utf8' specified as their charset
- Make sure you specify page encoding when sending html to the client (either by header('Content-Type: text/html;charset=UTF-8') or by <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>)
- When using mysql clients other than php, make sure they set connection charset (or run 'set names utf8' manually) and actually support UTF-8 encoding (this includes PHPMyAdmin, which should be configured properly to show UTF-8).
Re: funky character: ,â€
Posted: Mon Feb 16, 2009 7:42 pm
by Bill H
I'm not sure if this is related but is there any reason why the first line would insert into my DB and not the second?
Yes, the first line has no single quotes (apostrophes) in it, and the second one does.
See
mysql_real_escape_string() function.
Re: funky character: ,â€
Posted: Tue Feb 17, 2009 3:01 pm
by jwerre
Thanks so much, you guys rock! Apparently I need to learn a little more about character encoding.
Thanks Again