[英]How to Remove Html Tags in PHP?
I use htmlspecialchars function in my string. 我在我的字符串中使用htmlspecialchars函数。 But, I don't want to clean them;
但是,我不想清理它们;
<b>, <br>, <p> <ul>,<li> bla bla...
Example: Mystring = "<script>.....</script><br><b>test</b><p>aaaa</p>";
示例:
Mystring = "<script>.....</script><br><b>test</b><p>aaaa</p>";
I want to; 我想要; =
=
<script>.....</script>
Have a look at HTML Purifier , and especially the whitelist feature. 看看HTML Purifier ,尤其是白名单功能。
This is probably the safest approach if you allow HTML tags. 如果您允许HTML标记,这可能是最安全的方法。 You can view the comparison here .
您可以在此处查看比较。
You want to remove all tags? 你想删除所有标签? Use strip_tags() .
使用strip_tags() 。
您可以使用HTML Sanitizer Class - http://www.phpclasses.org/browse/package/3746.html
You can use built in PHP function : strip_tags($text, '<p><a><li><b>');
你可以使用内置的PHP函数 :
strip_tags($text, '<p><a><li><b>');
You don't need to use any class or external library, to remove HTML tags from user input. 您不需要使用任何类或外部库来从用户输入中删除HTML标记。
In the above example I am cleaning the $text from all tags except <p><a><li><b>
; 在上面的例子中,我清除了除
<p><a><li><b>
之外的所有标签的$ text;
This PHP function will clean user input making sure are not submitting <script>
or </div>
to break your page. 此PHP函数将清除用户输入,确保不提交
<script>
或</div>
来破坏页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.