使用 preg_replace 删除元素
Remove elements with preg_replace
我有一个 html 字符串,我想删除它...
$html = '<h2 class="post-title entry-title">Some Title</h2>';
$removeit = preg_replace('#<h2 class="post-title entry-title">(.*?)</h2>#', '', $html );
为什么我不能删除它?在其他情况下,如果我将使用下面的代码,我可以删除 div like
$html = '<div style="width:300px; height:120px; background-color:#000;">Some Title</div>';
$removeit = preg_replace('#<div style="width:300px; height:120px; background-color:#000;">(.*?)</div>#', '', $html );
朋友,试试用strip_tags功能。你可以在 php 文档中看到如何使用:
http://php.net/manual/en/function.strip-tags.php
我有一个 html 字符串,我想删除它...
$html = '<h2 class="post-title entry-title">Some Title</h2>';
$removeit = preg_replace('#<h2 class="post-title entry-title">(.*?)</h2>#', '', $html );
为什么我不能删除它?在其他情况下,如果我将使用下面的代码,我可以删除 div like
$html = '<div style="width:300px; height:120px; background-color:#000;">Some Title</div>';
$removeit = preg_replace('#<div style="width:300px; height:120px; background-color:#000;">(.*?)</div>#', '', $html );
朋友,试试用strip_tags功能。你可以在 php 文档中看到如何使用: http://php.net/manual/en/function.strip-tags.php