Php 仅在通过文件获取源\u get\u内容后删除h3结束标记

Php 仅在通过文件获取源\u get\u内容后删除h3结束标记,php,html,Php,Html,我正在使用file_get_contents获取远程页面的html源代码,代码如下: <?php //Get the url $url = "remotesite/static/section35.html"; $html = file_get_contents($url); $doc = new DOMDocument(); // create DOMDocument libxml_use_internal_errors(true); $d

我正在使用file_get_contents获取远程页面的html源代码,代码如下:

<?php
    //Get the url
    $url = "remotesite/static/section35.html";
    $html = file_get_contents($url);
    $doc = new DOMDocument(); // create DOMDocument
    libxml_use_internal_errors(true);
    $doc->loadHTML($html); // load HTML you can add $html

    $elements = $doc->getElementsByTagName('tbody');

    $toRemove = array();

    // gather a list of tbodys to remove
    foreach($elements as $el)
      if((strpos($el->nodeValue, 'desktop') !== false) && !in_array($el->parentNode, $toRemove, true))
        $toRemove[] = $el->parentNode;    

            foreach($elements as $el)
      if((strpos($el->nodeValue, 'Recommended') !== false) && !in_array($el->parentNode, $toRemove, true))
        $toRemove[] = $el->parentNode;  

    // remove them
    foreach($toRemove as $tbody)
      $tbody->parentNode->removeChild($tbody);

    echo $doc->saveHTML(); // save new HTML
?>

我现在要做的是删除源中的每一个h3关闭页面,然后将其回显到我的页面,因为这是正确显示内容的唯一方法

谢谢,这很好,但如果我只想删除
echo str_replace('</h3>','',$doc->saveHTML());