我想解析一些HTML文件,我上傳到我的虛擬主機。當我嘗試這(與在那裏的最後一個回聲只是爲了看看它的工作原理):解析通過PHP,回聲不工作
<?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」;
?>
在我的網頁的輸出是: “HEYHEYâ€
但是,如果我改線
foreach ($standingsArray as $arrayValue) {
echo $arrayValue;
}
到:
foreach ($standingsArray as $arrayValue) {
echo "$arrayValue";
}
那麼即便是 「 「嗨嗨」 消失了,我擁有的只是一個空白的網頁。
http://ideone.com/YB8vZY – Alex
在打開'<?php'標記error_reporting(E_ALL)後立即在文件頂部添加錯誤報告; ini_set('display_errors',1);'就像@Jite說的那樣。 –
這不是一個PHP錯誤。你有一個字符集不匹配。例如將utf-8文本轉儲到iso-8859顯示環境中。 –