如何删除< div>变量标记而不使用strip_tags? [英] How can i remove <div> tag from variable without using strip_tags?
本文介绍了如何删除< div>变量标记而不使用strip_tags?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
$str="<div>this is the variable</div>";
我想删除其html标签< div>
不使用strip_tags。
我需要 $ str =这是变量
因为我的服务器没有使用strip_tags。
我知道preg_replace是可行的。但我不知道正则表达式。
所以请建议我的解决方案。
I want to remove its html tag <div>
without using strip_tags.
I need $str="this is the variable"
Because my server is not working with strip_tags.
I know it is possible with preg_replace. but i dont know regex.
So please suggest me the solution.
提前谢谢。
推荐答案
$s = "<div>this is the variable</div>";
echo preg_replace("/<div>(.*?)<\/div>/", "$1", $s);
// this is the variable
当然,不要解析带正则表达式的HTML: - )
DEMO 。
DEMO.
这篇关于如何删除< div>变量标记而不使用strip_tags?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文