这是我的代码
$str="<div>this is the variable</div>";
我想删除它的 html 标签<div>不使用 strip_tags。 我需要$str="this is the variable"因为我的服务器不支持 strip_tags。 我知道使用 preg_replace 是可能的。但我不知道正则表达式。 所以请建议我解决方案。
<div>
$str="this is the variable"
先感谢您。
如果 DIV 标记包含属性,此变体也适用:
$str = '<div id="some_id">this is the variable</div>'; $str = preg_replace('/\<[\/]{0,1}div[^\>]*\>/i', '', $str); echo $str;