php strip_tags removing everything

◇◆丶佛笑我妖孽 提交于 2019-12-03 18:03:24

Problem is in this case

$foo = "text >.<text"

Try this expression (preg_replace with ims falgs):

<\s*\/?[a-z0-9]+(\s*[a-z\-0-9]+)*(\s*[a-z\-0-9]+\="[^"]*")*\s*\/?>

@edit: For example:

<?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);

You can use regular expression:

$result = preg_replace("/\<\/?[A-Za-z\-\_]+\>/", "", YOUR_DATA);

The HTML parser uses < to denote the start of an element, so generally you're safer not using it anyway. If you want a less than sign to appear in your copy, use the HTML name or number instead: &lt; or &#60;.

No, strip_tags will work that way. There is no difference between an opening brace and a smiley part, so you can add exceptions before strip_tags:

input.replace("<3", "& lt;3");
input = strip_tags(input);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!