The last couple of days I am updating a script to work with Joomla 2.5. It's almost done, but there is one thing that I haven't been able to solve yet. And it's a weird one.
The script has a cron wich parses a affiliate XML. To do this it uses the PHP function xml_parse as seen below:
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 );
As said the problem lays on the xml_parse function. On this line the whole page/script stops working and returns only the contents written above this line. It is not returning any error while error_reporting is E_ALL and display_errors is On. When creating an error on purpose I see the error so error_reporting is working. The parser($this->parser) is created in another file. Wich is loaded(var_dumped $this->parser).
The code where $this->parser is created (I believe this class is called 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);
}
I am out of ideas to solve this. I tried different encodings(ISO, UTF-8 etc.), checking the $data but everything seems file.
An example XML file can be found here: http://pastebin.com/wT1pVZLQ