1

I wanna delete some words from simple_html_dom when get external data (e.g name of Author or name of website ) from this code: `

<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

include('simple_html_dom.php');  
$html = new simple_html_dom();

// Create DOM from URL or file


$html = file_get_html('http://www.example.com');       

$myContent = $html->find('table', 0)->plaintext;
echo $myContent;

I don't know how can do it (delete flowing code from a table from url)

  <tr style="background: #ffd700;color:black;">

    <td colspan="5">**delete this words from table..**   
    </td></tr>
2

3 Answers 3

1

you can also delete directly from the dom the innertext between your TD

$html->find('table tr')->children(NUMBER OF THE TD TO EMPTY)->innertext = '';

here is the doc for simpleHtmlDomParser

http://simplehtmldom.sourceforge.net/manual.htm#section_traverse

Sign up to request clarification or add additional context in comments.

Comments

1

In my case, I'm grabbing a table, and needed to remove the tfoot. Did so like:

include("simple_html_dom.php");
$html = str_get_html($curl_response_html); // load html from string
$wtable = $html->find('table[id=sometableid]',0); // get table by id
$wtable->find('tfoot',0)->outertext=''; // find the element in the table and remove it
echo $wtable;

In your case, if you want to remove the whole row and you know the table row number, you can do something like:

$wtable = $html->find('table[id=sometableid]',0); // get table by id
$wtable->find('tr',0)->outertext=''; // find the element in the table and remove it

Where 'tr', 0 that would remove the first row, and 'tr', 3 would remove the fourth row.

Or even:

$wtable = $html->find('table[id=sometableid]',0); // get table by id
$wtable->find('td[colspan=5]',0)->innertext=''; // find the element and remove its contents

That would get the first cell with colspan 5 and remove its contents.

Comments

0

there is a table here I'm going to delete this td <td colspan="5"> all html files is here:

    <table cellspacing="6px" border="0px" cellpadding="0" align="center" width="670px" style="font-size:16pt;font-weight:bold;font-family:times new roman;margin-top:0px;border:1px solid #666666;text-align:center;">
<tbody><tr><td colspan="4">text 1
</td></tr><tr style="background: #ffd700;color:black;">

<td colspan="5">text for delete‌   
</td></tr><tr style="background: #fdfdad">
<td colspan="5" style="font-size:13pt;">text2
</td></tr><tr style="background: #ffffcc">
<td colspan="2">text3
</td><td>text4
</td><td>text5
</td></tr><tr style="background: #fdfdad">
<td width="35px"><img src="PIC/PNG/UnitedStates-01.png" width="33" height="22">
</td><td>text6
</td><td>3015
</td><td>2990
</td></tr><tr style="background: #ffffcc">
<td><img src="PIC/PNG/Europe-01.png" width="33" height="22">
</td><td>text7
</td><td>4100
</td><td>4072
</td></tr><tr style="background: #fdfdad">
<td><img src="PIC/PNG/Canada-01.png" width="33" height="22">

</td><td>2436
</td><td>2366
</td></tr></tbody></table>

How to delete a td from a table in the simple_html_dom ?

1 Comment

Using this as an example // Find all td tags with attribite align=center in table tags PHP Simple HTML DOM Parser Manual $es = $html->find(''table td[align=center]'); Your example would need something like this $html->find('table tr td[colspan=5]')->innertext = '';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.