php strip_标记删除所有内容

php strip_标记删除所有内容,php,strip-tags,Php,Strip Tags,我在用户输入上使用strip标签删除所有可能的标签,但是strip_标签php函数也在删除“您可以使用正则表达式: $result = preg_replace("/\<\/?[A-Za-z\-\_]+\>/", "", YOUR_DATA); $result=preg\u replace(“/\/”,“”,您的数据); HTML解析器使用。 @编辑: 例如: <?php $test = "text text text >.<asd text <div

我在用户输入上使用strip标签删除所有可能的标签,但是strip_标签php函数也在删除“您可以使用正则表达式:

$result = preg_replace("/\<\/?[A-Za-z\-\_]+\>/", "", YOUR_DATA);
$result=preg\u replace(“/\/”,“”,您的数据);

HTML解析器使用<来表示元素的开头,因此通常不使用它更安全。如果希望在副本中显示小于号,请使用HTML名称或编号:
<

不,条带标签将以这种方式工作。开口大括号和笑脸零件之间没有区别,因此可以在strip_标记之前添加异常:

input.replace("<3", "& lt;3");
input = strip_tags(input);

input.replace(在这种情况下出现问题

$foo = "text >.<text"
$foo=“text>。
@编辑: 例如:

<?php 

$test = "text text text >.<asd text <div style=\"font-size:12px;\">text >.<in div</div> asd asd <b>bolded</b> <script> alert('this is javascriptalert'); </script>";

$stripped =  strip_tags($test);
$replaced = preg_replace('/<\s*\/?[a-z0-9]+(\s*[a-z\-0-9]+)*(\s*[a-z\-0-9]+\="[^"]*")*\s*\/?>/ims','',$test);
var_dump($stripped,$replaced);
string strip_标记(string$str[,string$allowed_标记])
<?php 

$test = "text text text >.<asd text <div style=\"font-size:12px;\">text >.<in div</div> asd asd <b>bolded</b> <script> alert('this is javascriptalert'); </script>";

$stripped =  strip_tags($test);
$replaced = preg_replace('/<\s*\/?[a-z0-9]+(\s*[a-z\-0-9]+)*(\s*[a-z\-0-9]+\="[^"]*")*\s*\/?>/ims','',$test);
var_dump($stripped,$replaced);