Fork me on github

PHP 过滤 及 字符转换 函数

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=&#039;test&#039;&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>
posted @ 2015-08-14 14:36  Champion-水龙果  阅读(287)  评论(0编辑  收藏  举报
Champion-水龙果