I am trying to get first 3 tags texts using the PHP Simple HTML DOM Parser and collecting those in array.
The table is like:
<table>
<tbody>
<tr>
<td>Floyd</td>
<td>Machine</td>
<td>Banking</td>
<td>HelpScout</td>
</tr>
<tr>
<td>Nirvana</td>
<td>Paper</td>
<td>Business</td>
<td>GuitarTuna</td>
</tr>
<tr>
<td>The edge</td>
<td>Tree</td>
<td>Hospital</td>
<td>Sician</td>
</tr>
.....
.....
</tbody>
</table>
What I am trying to achieve is collect these in arrays excluding the 4th td of the tr tag:
array(
array(
'art' => 'Floyd',
'thing' => 'machine',
'passion' => 'Banking',
),
array(
'art' => 'Nirvana',
'thing' => 'Paper',
'passion' => 'Business',
),
array(
'art' => 'The edge',
'thing' => 'Tree',
'passion' => 'Hospital',
),
);
This is what I have tried is:
require_once dirname( __FILE__ ) . '/library/simple_html_dom.php';
$html = file_get_html( 'https://www.example.com/list.html' );
$collect = array();
$list = $html->find( 'table tbody tr td' );
foreach( $list as $l ) {
$collect[] = $l->plaintext;
}
$html->clear();
unset($html);
print_r($collect);
Which is giving all the tds in array and it's being difficult to identify the array keys which I require. Is there any solution for me?
trso you can grab the first 3tdof each.