简体   繁体   中英

Parsing through PHP, echo not working

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.

Try this,

foreach ($standingsArray as $arrayValue) 
{
    echo utf8_encode($arrayValue);
}

UPDATE:

"HEYHEY" seems to be a different font, try removing/replacing it with normal text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM