最近幾天,我正在更新腳本以使用Joomla 2.5。這幾乎完成了,但有一件事我還沒有解決。這是一個奇怪的。xml_parse退出頁面。沒有錯誤
該腳本有一個cron解析會員XML。要做到這一點,使用PHP函數xml_parse,如下圖所示:
if (!($fp = @$file_function($url, 'rb'))) {
$this->error("Cannot open {$url}");
return;
}
while (($data = fread($fp, 8192))) {
if (defined ('LIBXML_BUG')) {
# fix voor LIBXML BUG
$data=str_replace("&","XMLLIBHACK",$data);
}
if (!xml_parse($this->parser, $data, feof($fp))) {
printf('XML error in %s at line %d column %d',
$url,
xml_get_current_line_number($this->parser),
xml_get_current_column_number($this->parser));
unset ($this->items);
}
}
xml_parser_free($this->parser);
正如所說的xml_parse函數問題的規定。在這一行上,整個頁面/腳本停止工作,並只返回寫在該行上面的內容。當error_reporting爲E_ALL且display_errors爲On時,它不返回任何錯誤。當故意創建錯誤時,我看到error_reporting正在工作的錯誤。解析器($ this-> parser)是在另一個文件中創建的。 Wich被加載(var_dumped $ this-> parser)。
在其中創建$這個 - >解析器的代碼(我相信這個類的magpierss叫):
function create_parser($out_enc, $in_enc, $detect) {
if (substr(phpversion(),0,1) == 5) {
$parser = $this->php5_create_parser($in_enc, $detect);
}
else {
$parser = $this->php4_create_parser($in_enc, $detect);
}
if ($out_enc) {
$this->encoding = $out_enc;
xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $out_enc);
}
return $parser;
}
/**
* Instantiate an XML parser under PHP5
*
* PHP5 will do a fine job of detecting input encoding
* if passed an empty string as the encoding.
*
* All hail libxml2!
*
*/
function php5_create_parser($in_enc, $detect) {
// by default php5 does a fine job of detecting input encodings
if(!$detect && $in_enc) {
return xml_parser_create($in_enc);
}
else {
return xml_parser_create('');
}
}
/**
* Instaniate an XML parser under PHP4
*
* Unfortunately PHP4's support for character encodings
* and especially XML and character encodings sucks. As
* force to UTF-8 use admin settings to change this
*/
function php4_create_parser($in_enc, $detect) {
if ($detect) {
$in_enc = 'UTF-8';
}
return xml_parser_create($in_enc);
}
我的想法來解決這個問題。我嘗試了不同的編碼(ISO,UTF-8等),檢查$數據,但一切似乎文件。
一個例子XML文件可以在這裏找到:http://pastebin.com/wT1pVZLQ
我試過你的腳本(使用提供的數據),也沒有打破我。我在'xml_parser_free($ this-> parser)之後執行了一些代碼行;'它工作正常。你能否寄全班,以便詳細瞭解? –
你在哪裏設置了錯誤報告設置?在代碼中,或在php.ini? – jprofitt
Error_reporting和顯示錯誤是在php.ini中設置的,我在代碼本身嘗試了它,但這並沒有幫助。 – Timo