删除php中html表的第一行
如何在php中轻松删除html表的第一行,它是来自简单HTMLDOM的对象删除php中html表的第一行,php,html-table,simple-html-dom,Php,Html Table,Simple Html Dom,如何在php中轻松删除html表的第一行,它是来自简单HTMLDOM的对象 <?php include("simple_html_dom.php"); $html=file_get_html("url"); $string = $html; preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $string, $matches); $h
<?php
include("simple_html_dom.php");
$html=file_get_html("url");
$string = $html;
preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $string, $matches);
$html=file_get_html($matches[0][1]);
$article=$html->find("article",0);
foreach($article->find('article-title') as $title)
echo $title->outertext;
foreach($article->find('table') as $table) {
echo $table->outertext;
}
?>
要从DOM树中删除元素,请将其
outertext
设置为空字符串,以便在找到文章中的表部分:
// for each table
foreach($article->find('table') as $table) {
// find first row in table
$row = $table->find('tr', 0);
// delete row
$row->outertext = '';
echo $table->outertext;
}
是一个类似的问题,有更详细的答案