I'm trying to parse some html with a php document that I upload to my web host. When I try this (with the last echo in there just to see if it works):
<?php
//a URL you want to retrieve
$my_url = 'http://pointstreak.com/prostats/standings.html?leagueid=49&seasonid=12983';
$html = file_get_contents($my_url);
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
//Put your XPath Query here
$my_xpath_query = "//div[@id='statscontainer']/table/tr/td/table[@class='tablelines']/tr/td";
$result_rows = $xpath->query($my_xpath_query);
// Create an array to hold the content of the nodes
$standingsArray = array();
//here we loop through our results (a DOMDocument Object)
foreach ($result_rows as $result_object){
$standingsArray[] = $result_object->childNodes->item(0)->nodeValue;
}
// Remove the first 12 observations from $standingsArray (table headers)
for ($i = 0; $i < 12; $i++) {
unset($standingsArray[0]);
$standingsArray = array_values($results_rows);
}
// Remove the 12 observations at index 96 (table headers)
for ($i = 0; $i < 12; $i++) {
unset($standingsArray[96]);
$standingsArray = array_values($results_rows);
}
foreach ($standingsArray as $arrayValue) {
echo $arrayValue;
}
echo “HEYHEY”;
?>
The output on my webpage is: “HEYHEYâ€
However, if I change the line
foreach ($standingsArray as $arrayValue) {
echo $arrayValue;
}
to:
foreach ($standingsArray as $arrayValue) {
echo "$arrayValue";
}
then even the "“HEYHEYâ€" goes away and all I have is a blank webpage.