It would be nice if I could call my_escape($text, '<p><b><i>')
that escapes everything except all <p>
, <b>
and <i>
tags. I'm looking for a generic solution where I can specify an arbitrary set of tags. Does this exist? If not what's the best approach to implement it?
in htmlspecialchars function it converts html tags to
& to &
" to "
' to '
< to <
> to >
after convert you can do reverse to decode
<?php
$test="<p><b><a>Test</b></a></p>";
$test = htmlspecialchars($test);
$test = str_replace("<p>", "<p>", $test);
$test = str_replace("<i>", "<i>", $test);
$test = str_replace("<b>", "<b>", $test);
$test = str_replace("</b>", "</b>", $test);
$test = str_replace("</i>", "</i>", $test);
$test = str_replace("</p>", "</p>", $test);
echo $test;
?>