Answer the question
In order to leave comments, you need to log in
Why does PHP Simple HTML DOM Parser only take text from a table cell?
I am parsing a table from one site, in one of the columns of the table there is text that is like a link of the form
<td class=""><a href="/lang/info/pdf/длиный код" target="_blank">PDF</a></td>
$url = 'site.com';
include 'simple_html_dom.php';
$html = file_get_html($url);
$table = $html->find('table', 0);
$rowData = array();
foreach($table->find('tr') as $row) {
// initialize array to store the cell data from each row
$flight = array();
foreach($row->find('td') as $cell) {
// push the cell's text to the array
$flight[] = $cell->plaintext;
}
$rowData[] = $flight;
}
Answer the question
In order to leave comments, you need to log in
In the row
$flight[] = $cell->plaintext;
you use the plaintext method which clears all the tags, and for this cell it should return the text 'PDF'.
Not quite clear what you need? If you need to further parse other nested html elements, then you need to complicate your logic, add conditions. Here from the same documentation , add nested loops for the same tag a
and parse href from it if you need it separately. Etc.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question