Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace ' and similar html codes with their correspondent character?

Tags:

php

so I have a string that goes like this:

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

Is there a php function that transforms these to their correspondent character, in my example the desired output would be:

print $string
// OUTPUT: This is a test string. It has characters like these: '
like image 549
Jonas Kaufmann Avatar asked May 18 '13 01:05

Jonas Kaufmann


1 Answers

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

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

so the exact behavior on ' worth checking

EDIT: I made the test and it does work :)

like image 100
Yaron U. Avatar answered Oct 04 '22 16:10

Yaron U.