繁体   English   中英

在php中删除html表的第一行

[英]Delete first row of html table in php

如何轻松删除php中html表的第一行,这是简单html dom中的对象?

<?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设置为空字符串,因此,在代码部分中,您将在article找到table

// 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;
}

简单的HTML Dom:如何删除元素? 是具有更详细答案的类似问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM