epseix Posted December 30, 2011 Share Posted December 30, 2011 Hi everyone. I'm struggling to figure this one out and hope someone can help. I completely understand the principles of this function - however - I am using pre-defined strings and entering them into a database. For some reason whenever there is a single quote, the pre-defined string uses ' instead of ' I am trying to parse this, decode the string, and use htmlspecialchars function to convert it and enter into my database, however htmlspecialchars_decode does not seem to recognise ' - only the likes of " and & In order to convert: Sam's House -> Sam's House -> Sam's House I have tried using: $str = "Sam's house"; $str = htmlspecialchars_decode($str); $new = htmlspecialchars($str, ENT_QUOTES); However, this returns: Sam's House. The decoding function seems to fail. any ideas? Much appreciated in advance! Quote Link to comment https://forums.phpfreaks.com/topic/254051-htmlspecialchars_decode-query/ Share on other sites More sharing options...
AyKay47 Posted December 30, 2011 Share Posted December 30, 2011 htmlspecialchars_decode will require its second parameter to be set to ENT_QUOTES in order to parse the apostrophe html character. The default value for the second parameter is ENT_COMPAT, which will leave single quotes unconverted. where is this predefined string coming from? While ' is an except-able character, ' should more than likely be used. Quote Link to comment https://forums.phpfreaks.com/topic/254051-htmlspecialchars_decode-query/#findComment-1302407 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.