I'm trying to get values from a table in a webpage and for that I'm using Simple HTML Dom library. This is how my code looks like:
include('simple_html_dom.php');
$html = file_get_html('http://www.lvbp.com/posicion.html');
$arr = array();
foreach ($html->find('tr') as $e) {
array_push($arr, $e->innertext);
}
echo '<pre>';
print_r($arr);
echo '</pre>';
for ($i = 2; $i < count($arr); $i++) {
str_replace("", "-", $arr[$i]);
print_r($arr[$i]);
}
And I get this as output when print_r($arr)
:
Array
(
[0] => EQUIPOS J G P Vent
[1] =>
[2] => Navegantes 11 8 3 0
[3] => Tigres 11 8 3 0
[4] => Caribes 11 6 5 2
[5] => Leones 11 6 5 2
[6] => Aguilas 11 5 6 3
[7] => Tiburones 10 4 6 3.5
[8] => Cardenales 10 3 7 4.5
[9] => Bravos 11 3 8 5
)
But from here I need to get separately meaning "Navegantes", "11", "8" and so on ... for each array position. For that my last code:
for ($i = 2; $i < count($arr); $i++) {
str_replace("", "-", $arr[$i]);
print_r($arr[$i]);
}
But it's not working since I get this as result:
Navegantes 11 8 3 0 Tigres 11 8 3 0 Caribes 11 6 5 2 Leones 11 6 5 2 Aguilas 11 5 6 3 Tiburones 10 4 6 3.5 Cardenales 10 3 7 4.5 Bravos 11 3 8 5
What I'm missing? Any help?
UPDATE
This is how my code looks like based on suggestions:
include('simple_html_dom.php');
$html = file_get_html('http://www.lvbp.com/posicion.html');
$arr = array();
foreach ($html->find('tr') as $e) {
$narr = array();
foreach ($e->find('td') as $vp) {
array_push($narr, $vp->plaintext);
}
$arr[] = array($narr);
}