Foreach problem
Posted: Wed Dec 02, 2009 3:06 pm
This what my code looks like:
$i=0;
$x=0;
$y=0;
// Load the HTML string from file and create a SimpleXMLElement
$html_string = file_get_contents("data/csr.html");
$root = new SimpleXMLElement($html_string);
// Fetch all div, h2 and span values
$divArray = $hdlsArray = $dtlsArray = array();
foreach ($xml->div as $div) {
$divArray[$x] = $div;
$x++;
}
foreach ($xml->h2 as $h2) {
$hdlsArray[$y] = $h2;
$y++;
}
foreach ($xml->span as $span) {
$dtlsArray[$z] = $span;
$z++;
}
When I run it, I get:
Warning: Invalid argument supplied for foreach() in C:\xamps older\xampp167\htdocs\test\myphp\CSR Demo pack\csr\output.php on line 58
Warning: Invalid argument supplied for foreach() in C:\xamps older\xampp167\htdocs\test\myphp\CSR Demo pack\csr\output.php on line 62
Warning: Invalid argument supplied for foreach() in C:\xamps older\xampp167\htdocs\test\myphp\CSR Demo pack\csr\output.php on line 66
Thanks in advance.
$i=0;
$x=0;
$y=0;
// Load the HTML string from file and create a SimpleXMLElement
$html_string = file_get_contents("data/csr.html");
$root = new SimpleXMLElement($html_string);
// Fetch all div, h2 and span values
$divArray = $hdlsArray = $dtlsArray = array();
foreach ($xml->div as $div) {
$divArray[$x] = $div;
$x++;
}
foreach ($xml->h2 as $h2) {
$hdlsArray[$y] = $h2;
$y++;
}
foreach ($xml->span as $span) {
$dtlsArray[$z] = $span;
$z++;
}
When I run it, I get:
Warning: Invalid argument supplied for foreach() in C:\xamps older\xampp167\htdocs\test\myphp\CSR Demo pack\csr\output.php on line 58
Warning: Invalid argument supplied for foreach() in C:\xamps older\xampp167\htdocs\test\myphp\CSR Demo pack\csr\output.php on line 62
Warning: Invalid argument supplied for foreach() in C:\xamps older\xampp167\htdocs\test\myphp\CSR Demo pack\csr\output.php on line 66
Thanks in advance.