Fix Encoding on Variable

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
Trinitrotoluene
Forum Newbie
Posts: 2
Joined: Tue Aug 25, 2009 6:52 pm

Fix Encoding on Variable

Post by Trinitrotoluene »

Hello everyone,

I'm currently pulling some data from a SQL row that is used as the backend for a forum. I am placing this into a variable called lets say $variable1.

Now sometimes the post on the forums are different, for example on some posts people put in (if they copied and pasted) you will get this type of quotation mark: “ as opposed to ". Now this is only a problem when I display this row on a page because it comes out all messed up like this “I looked into the rear view mirror and I saw it leap across my trunk.”

Any idea how I can fix this? I guess I have to run the string through a function to change the encoding but not sure where to start. Any help would be appreciated.

Regards,

TNT
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Fix Encoding on Variable

Post by requinix »

What would be really nice is if you could use a good encoding for everything: HTML pages and database tables. An encoding that can handle characters like those smart quotes. If you got that set up correctly then you wouldn't have any problems like that.

That would take a bit of work on your part though, so

Code: Select all

echo iconv("UTF-8", "ISO-8859-1", 'quotation mark: “ as opposed to "'); // probably
Post Reply