我试图替换pre标签之间的html标签。这就是我想要它做的事情:
$str = '<pre><div>Get<p>rid</p> of html tags</div></pre>';
$str = preg_replace('#(<pre.*?>)/<[^<>]+>/(</pre>)#', '$1$2', $str);
echo $str;
它应该响应,&#34;摆脱html标签&#34;在预标签
我知道一个事实,
$str = preg_replace('#(<pre.*?>).*?(</pre>)#', '$1$2', $str);
可以使用,但会使用空的预标签进行响应。
我只需要删除预标记之间的所有html标记。
答案 0 :(得分:3)
我是这样做的:
$str = preg_replace_callback("#(<pre[^>]*>).*?</pre>#is",function($m) {
return $m[1].strip_tags($m[0])."</pre>";
},$str);
答案 1 :(得分:0)
$str = '<pre><div>Get<p>rid</p> of html tags</div></pre>';
if(preg_match("/<pre>(.+?)<\/pre>/i", $str,$res))
{
$str=strip_tags($res[1]);
}
echo $str;