Replace 'and similar html codes with their corresponding symbol?

so I have a line that looks something like this:

$string = "This is a test string. It has characters like these: '"; 

Is there a php function that converts them to the corresponding character, in my example the desired result:

 print $string // OUTPUT: This is a test string. It has characters like these: ' 
+4
source share
2 answers

yes there is: htmlspecialchars_decode($string, ENT_QUOTES);

not sure about specific ' char, as far as I know, htmlspecialchars (with the ENT_QUOTES flag) converts an apostrophe (') to ' (with a leading zero)

therefore the exact behavior on ' worth checking out

EDIT: I did a test and it works :)

+10
source

You can use html_entity_decode ()

This is similar to the reverse htmlentities. If you use quotation marks in your input line, you must set the second parameter html_entity_decode() to ENT_QUOTES

See in action: http://sandbox.onlinephpfunctions.com/code/7f4649eb47a8e639c514787a100b63bbad4bc8c6

+2
source

Source: https://habr.com/ru/post/1481487/


All Articles