funky character: ,â€

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jwerre
Forum Newbie
Posts: 18
Joined: Thu Feb 05, 2009 5:06 pm

funky character: ,â€

Post 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");
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: funky character: ,â€

Post by Weirdan »

Because the text you're importing is encoded in UTF-8, and you're treating it as ascii (or latin-1).
jwerre
Forum Newbie
Posts: 18
Joined: Thu Feb 05, 2009 5:06 pm

Re: funky character: ,â€

Post 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
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: funky character: ,â€

Post 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).
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Re: funky character: ,â€

Post 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.
jwerre
Forum Newbie
Posts: 18
Joined: Thu Feb 05, 2009 5:06 pm

Re: funky character: ,â€

Post by jwerre »

Thanks so much, you guys rock! Apparently I need to learn a little more about character encoding.

Thanks Again
Post Reply