phpstringdecodinghtml-entities

Decode encoded html entities in a string


I want to change strings with the odd """ such as:

He said: "I don't think so"

To be:

He said: "I don't think so"

My current code is:

$sentence = addslashes(preg_replace('/^\&quot\;$/','\"',$var));

What is my problem in the code?


Solution

  • ^ and $ will only match the start and end of the whole string (or a whole line in /m mode). Since " doesn't appear like that, your regex whole match it. Just remove the ^ and $ and it should work.

    BTW, perhaps you want to use html_entity_decode() instead.