简体   繁体   中英

reverse htmlspecialchars

this may seem like a simple problem but I couldn't find it in the archives.

how does one reverse the effects of htmlspecialchars?

I tried something like this:

$trans_tbl = get_html_translation_table (HTML_ENTITIES);
$trans_tbl = array_flip ($trans_tbl);
$html = strtr ($html, $trans_tbl);

but it didn't work. is there a simple way to do this?

Use htmlspecialchars_decode()

<?php
$str = "<p>this -&gt; &quot;</p>\n";

echo htmlspecialchars_decode($str);

// note that here the quotes aren't converted
echo htmlspecialchars_decode($str, ENT_NOQUOTES);
?>

Reference - PHP Official Doc

You need htmlspecialchars_decode() . See PHP docu on this .

$html = htmlspecialchars_decode( $html, ENT_NOQUOTES );

example :

echo htmlspecialchars_decode(htmlspecialchars('your "strange" text with characters like !"/$%?&*'))

it will echo : your "strange" text with characters like !"/$%?&*

this is an example of encode/decode. it works.

根据我的理解,你需要htmlspecialchars_decode - Docu

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM