因为我不想使用 php 的 stip_tags 函数而不是我想替换 <script> and </script>
为空字符串,所以输出应该是 alert(1)。
输入:-
<script>alert(1)</script>
输出:- 警报(1)
如何实现它。
要么使用简单的替换:
$string = str_replace(array("<script>","</script>"), "");
Run Code Online (Sandbox Code Playgroud)
或正则表达式:
$string = preg_replace("/<script.*?>(.*)?<\/script>/im","$1",$string);
Run Code Online (Sandbox Code Playgroud)