最近几天,我正在更新脚本以使用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