Delete first row of html table in php

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Delete first row of html table in php



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()<>]+(?:([wd]+)|([^,[: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;

?>




1 Answer
1



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:


outertext


table


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.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard