如何在不使用strip_tags的情况下从变量中删除<div>标记?

Kri*_*rki 2 php regex html5

这是我的代码

$str="<div>this is the variable</div>";
Run Code Online (Sandbox Code Playgroud)

我想删除它的html标签<div>而不使用strip_tags.我需要$str="this is the variable" 因为我的服务器不能使用strip_tags.我知道preg_replace是可行的.但我不知道正则表达式.所以请建议我的解决方案.

先感谢您.

Cou*_*Web 6

如果DIV标记包含属性,则此变体也适用:

$str = '<div id="some_id">this is the variable</div>';
$str = preg_replace('/\<[\/]{0,1}div[^\>]*\>/i', '', $str);
echo $str;
Run Code Online (Sandbox Code Playgroud)