Jump to content

htmlspecialchars_decode Query


epseix

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/254051-htmlspecialchars_decode-query/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.