使用php删除特定的html标签 [英] remove specific html tags using php
本文介绍了使用php删除特定的html标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因为我不想使用php的stip_tags函数,而不是要替换< script>和</script>
更改为空字符串,以便输出应为alert(1).
Since I dont want to use stip_tags function of php instead of I want to replace <script> and </script>
to empty string so that output should be alert(1).
输入:-
< script> alert(1)</script>
输出:-alert(1)
Output:- alert(1)
如何实现.
推荐答案
要么使用简单的替换:
$string = str_replace(array("<script>","</script>"), "");
或RegEx:
$string = preg_replace("/<script.*?>(.*)?<\/script>/im","$1",$string);
这篇关于使用php删除特定的html标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文