2015-04-22 83 views
2

我想解析一些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"; 
    } 

那麼即便是 「 「嗨嗨」 消失了,我擁有的只是一個空白的網頁。

+0

http://ideone.com/YB8vZY – Alex

+0

在打開'<?php'標記error_reporting(E_ALL)後立即在文件頂部添加錯誤報告; ini_set('display_errors',1);'就像@Jite說的那樣。 –

+1

這不是一個PHP錯誤。你有一個字符集不匹配。例如將utf-8文本轉儲到iso-8859顯示環境中。 –

回答

0

試試這個,

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

UPDATE:

「HEYHEY」 似乎是一個不同的字體,請嘗試刪除/對普通的文字替換它。

+0

沒有運氣。不過謝謝。 – Jay

+0

最後一個回聲不是普通文本,我用記事本++打開並刪除回顯並再次輸入,它運行正常。 –

+0

等等,什麼?你有我的代碼工作? – Jay