使用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);