这是我的代码
$str="<div>this is the variable</div>";
我想删除它的 html 标签 <div>
不使用 strip_tags。
我需要 $str="this is the variable"
因为我的服务器没有使用 strip_tags。
我知道可以使用 preg_replace。但我不知道正则表达式。
所以请给我建议解决方案。
提前谢谢你。
最佳答案
如果 DIV 标签包含属性,此变体也适用:
$str = '<div id="some_id">this is the variable</div>';
$str = preg_replace('/\<[\/]{0,1}div[^\>]*\>/i', '', $str);
echo $str;
关于php - 如何在不使用 strip_tags 的情况下从变量中删除 <div> 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12495084/