E
E
easy_katka2021-01-17 18:05:56
PHP
easy_katka, 2021-01-17 18:05:56

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>


After parsing, only text is displayed without content, my code is

$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

1 answer(s)
A
Alexander Talalaev, 2021-01-18
@easy_katka

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 aand parse href from it if you need it separately. Etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question