PHP 过滤 及 字符转换 函数

时间:2023-03-08 20:34:48
PHP过滤html标签的内部函数。

php过滤html的函数:

strip_tags(string)
这样就可以过滤掉所有的html标签了。 如果想过滤掉除了<img src="">之外的所有html标签,则可以这样写: strip_tags(string,"<img>");
过滤除了<img src=""><p>xxx</p><b></b>之外的所有html标签,则可以这样写: strip_tags(string,"<img><p><b>");
*****htmlentities***************************************************************
*****html_entity_decode*********************************************************
<?php
$orig = "I'll \"walk\" the <b>dog</b> now" ; $a = htmlentities ( $orig ); $b = html_entity_decode ( $a ); echo $a ; // I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now echo $b ; // I'll "walk" the <b>dog</b> now
?> *************htmlspecialchars**************************************************** <?php
$new = htmlspecialchars ( "<a href='test'>Test</a>" , ENT_QUOTES );
echo $new ; // &lt;a href='test'&gt;Test&lt;/a&gt;
?> ******htmlspecialchars_decode****************************************************
<?php
$str = "<p>this -&gt; &quot;</p>\n" ; echo htmlspecialchars_decode ( $str ); // 注意,这里的引号不会被转换
echo htmlspecialchars_decode ( $str , ENT_NOQUOTES );
?>
以上例程会输出: <p>this -> "</p> <p>this -> &quot;</p>