millercj Posted March 22, 2009 Share Posted March 22, 2009 I'm working on a project and in it there are fields in a database that contain values that have special characters (mainly apostrophes) such as S'mores. I have the apostrophes saved in the database as HTML characters (apostrphe is ’ so S'mores is S’mores) The data is pulled into an html page, then on a user action sent to js as a parameter, then to php (ajax) and then saved to another database. When the value gets to the new database S’mores has become S%u2019mores If i then call those fields into an HTML page they display as S%u2019mores and not S'mores. How to I normalize special characters to avoid this? Link to comment https://forums.phpfreaks.com/topic/150627-mysqlphp-interaction-with-special-characters/ Share on other sites More sharing options...
jackpf Posted March 22, 2009 Share Posted March 22, 2009 Why don't you just use addslashes() instead of htmlspecialchars()? Link to comment https://forums.phpfreaks.com/topic/150627-mysqlphp-interaction-with-special-characters/#findComment-791235 Share on other sites More sharing options...
millercj Posted March 22, 2009 Author Share Posted March 22, 2009 and then strip when i extract the data? Link to comment https://forums.phpfreaks.com/topic/150627-mysqlphp-interaction-with-special-characters/#findComment-791240 Share on other sites More sharing options...
jackpf Posted March 22, 2009 Share Posted March 22, 2009 Uhh..well, addslashes() to put into table1, addslashes() to put into table 2, and then htmlspecialchars() upon extraction if you so desire. Makes sense... Link to comment https://forums.phpfreaks.com/topic/150627-mysqlphp-interaction-with-special-characters/#findComment-791281 Share on other sites More sharing options...
millercj Posted March 23, 2009 Author Share Posted March 23, 2009 Ok it makes sense to me but it's still going to screw up my JS call because i'm ending up with onclick="sendToCart('102','Lover\'s Combo','5.00','13','');" Link to comment https://forums.phpfreaks.com/topic/150627-mysqlphp-interaction-with-special-characters/#findComment-791477 Share on other sites More sharing options...
jackpf Posted March 23, 2009 Share Posted March 23, 2009 Lol, lover's combo.... stripslashes() ? Link to comment https://forums.phpfreaks.com/topic/150627-mysqlphp-interaction-with-special-characters/#findComment-791690 Share on other sites More sharing options...
Yesideez Posted March 23, 2009 Share Posted March 23, 2009 Instead of using htmlspecialchars use htmlentities http://uk3.php.net/htmlentities Link to comment https://forums.phpfreaks.com/topic/150627-mysqlphp-interaction-with-special-characters/#findComment-791692 Share on other sites More sharing options...
jackpf Posted March 23, 2009 Share Posted March 23, 2009 htmlentities() is slower... Link to comment https://forums.phpfreaks.com/topic/150627-mysqlphp-interaction-with-special-characters/#findComment-791857 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.