Web Hosting Talk







View Full Version : PHP Smart Quotes


SynHost
03-16-2005, 01:37 PM
I've been having some recent troubles with PHP and encoding when sending e-mails. We have a form where our customers can enter a message and send it to a specific person. It's purposes is such that it makes sense to copy content from websites, such as msnbc. MSNBC in particular uses "smart quotes" which are angeled and are not the same for the beginning and end. These characters and others are included in the text box. When the send button is pressed and the message comes across, the smart quotes end up like this:
“ and ”
I'm only using the example of smart quotes, but this appears to happen with other characters our customers might send across, so just doing a str_replace for these doesn't cut it. I've searched the internet and my PHP books turn up nothing useful. I am very inexperienced with encoding schemes, etc. Surely this is not that uncommon of a problem. To help out, here are some values from phpinfo() that might have something to do with this:

(Environment)LANG: en_US.UTF-8
iconv.input_encoding ISO-8859-1 ISO-8859-1
iconv.internal_encoding ISO-8859-1 ISO-8859-1
iconv.output_encoding ISO-8859-1 ISO-8859-1

Any responses appreciated. Thank you,
Ben Hughes

SynHost
03-21-2005, 07:17 PM
This has to be a very common problem in web applications. I doubt it's a PHP configuration issue because I can submit the same content through a vBulletin site on the same server and it goes through fine.

The problem originates from our users posting mostly on Mac OS9 iMacs, but we need to be able to support them even if the encoding is different. I am told that the smart quotes aren't the only characters that don't show up right.

Any ideas appreciated.

JustinH
03-22-2005, 04:34 AM
http://us2.php.net/manual/en/function.htmlentities.php

Convert all the user input before you send it to the user. It may/may not work, but it's worth a try.

SynHost
03-23-2005, 01:53 PM
The output is being used to send text e-mail and is irrelevant to HTML. The problem is lower-level, some kind of encoding or something. This is by far the most frustrating thing I've ever had to deal with in PHP, particularly because there are just no solutions online. I've spent hours researching this rediculous problem.

stma
03-23-2005, 04:20 PM
Is there a reason you can't take the users input and do a str_replace on it to remove those "odd" characters. Of yourse you will need to know what they all are.