reverse htmlspecialchars
Asked Answered
A

4

40

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?

Answerable answered 29/6, 2012 at 6:45 Comment(2)
Read the manual, it will tell you all functions that have something to do with the one you are looking at in the 'see also' section this is that section for htmlspecialchars()Lavernelaverock
This question appears to be off-topic because it can be found in the manual.Watanabe
E
80

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

Emad answered 29/6, 2012 at 6:46 Comment(0)
H
4

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

$html = htmlspecialchars_decode( $html, ENT_NOQUOTES );
Hiphuggers answered 29/6, 2012 at 6:47 Comment(0)
P
4

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.

Purism answered 15/8, 2012 at 16:37 Comment(0)
P
0

From what I understood, you need htmlspecialchars_decode - Docu

Prowess answered 29/6, 2012 at 6:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.