到现在还有 3 个小时,我正在努力解决这个问题,但现在很幸运。
我有一个页面,它的内容由几个 html 表组成,每个表都有一定的 td
它看起来像这样
<td style="padding:0px 0px 0px 5px;" valign="middle"><span class="lshevent">team a - team b </span></td>
当有人单击此 Td 在新窗口中打开整个表格时,我想将此 td 设为超链接。
我的页面源是通过文件获取内容从远程页面检索的,如下所示
<?php
//Get the url
$url = "http://remotesite/pages/page1.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 str_replace('</h3><table','<table',$doc->saveHTML());
?>