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
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.