Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
删除php中html表的第一行_Php_Html Table_Simple Html Dom - Fatal编程技术网

删除php中html表的第一行

删除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中轻松删除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);
    $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;
}
是一个类似的问题,有更详细的答案