htmlspecialchars to and from the database
Posted: Mon Aug 24, 2009 7:38 am
On my blog, I have my posts set up with a raw content field and a parsed content field in the database. The raw content field is for editing, the parsed content field is already parsed as HTML. I'm having a problem, however, with HTML character codes that contain the pound sign. Standard character such as ñ (ñ) and þ (þ) work fine. When they are submitted, they go to the database in their raw form, and are translated into their HTML character code equivalent in their parsed form. However, for complex characters such as ★ (★) and ☆ (☆) are saved in their HTML character code format, which causes htmlspecialchars() to parse the ampersand as a special character. For example, "☆" becomes "☆", which displays as "☆" instead of "☆".
Are there any suggestions for fixing this behavior? What is causing these character codes to be submitted into the database incorrectly?
EDIT: For now, I am combating this by using str_replace('&#', '&#', htmlspecialchars($content)). I'd prefer a less hackish solution, though.
Are there any suggestions for fixing this behavior? What is causing these character codes to be submitted into the database incorrectly?
EDIT: For now, I am combating this by using str_replace('&#', '&#', htmlspecialchars($content)). I'd prefer a less hackish solution, though.