0

How can I easily delete the first row of my html table in php, which is an object from simple 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;
    }
?>
david
  • 3,225
  • 9
  • 30
  • 43

1 Answers1

0

To remove an element from DOM tree, set its outertext to empty string, so in the part of code that you're finding table inside article:

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

Simple HTML Dom: How to remove elements? is a similar question with more detailed answers.

Nima
  • 3,309
  • 6
  • 27
  • 44