我正在使用脚本混淆类将存储的javascripts作为字符串输出到单个输出中。
问题是客户当然会复制到或
我目前正在使用
$script = str_replace('</script>', "", $script);
$script = str_replace('<script>', "", $script);
$script = str_replace('<script type="text/javascript">', "", $script);
但是很想使用preg_replace表达式来处理它。
基本上需要删除<script + anything up to the >
和</script>
。
我对正则表达式语法不太熟悉,因为我没有在它们中使用它们。
我不想使用dom以防万一这是一个建议。
提前感谢您的任何帮助。
答案 0 :(得分:1)
您可以将它们放入数组:
$replaces = array("</script>", "<script>", '<script type="text/javascript">');
str_replace($replaces, "", $text)
或
preg_replace("/<\/?script.*?>/i", "", $text)