2015-04-22 82 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