function parse(&$data, $encoding)
{
// Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character
if (strtoupper($encoding) == 'US-ASCII') {
$this->encoding = 'UTF-8';
} else {
$this->encoding = $encoding;
}
// Strip BOM:
// UTF-32 Big Endian BOM
if (substr($data, 0, 4) === "��") {
$data = substr($data, 4);
} elseif (substr($data, 0, 4) === "��") {
$data = substr($data, 4);
} elseif (substr($data, 0, 2) === "��") {
$data = substr($data, 2);
} elseif (substr($data, 0, 2) === "��") {
$data = substr($data, 2);
} elseif (substr($data, 0, 3) === "") {
$data = substr($data, 3);
}
if (substr($data, 0, 5) === '<?xml' && strspn(substr($data, 5, 1), "\t\n\r ") && ($pos = strpos($data, '?>')) !== false) {
$declaration = new SimplePie_XML_Declaration_Parser(substr($data, 5, $pos - 5));
if ($declaration->parse()) {
$data = substr($data, $pos + 2);
$data = '<?xml version="' . $declaration->version . '" encoding="' . $encoding . '" standalone="' . ($declaration->standalone ? 'yes' : 'no') . '"?>' . $data;
} else {
$this->error_string = 'SimplePie bug! Please report this!';
return false;
}
}
// Work around libxml bug
$data = str_replace('<', '<', $data);
$data = str_replace('>', '>', $data);
$data = str_replace('&', '&', $data);
$data = str_replace(''', ''', $data);
$data = str_replace('"', '"', $data);
$return = true;
// Create the parser
$xml = xml_parser_create_ns($this->encoding, $this->separator);
xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1);
xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0);
xml_set_object($xml, $this);
xml_set_character_data_handler($xml, 'cdata');
xml_set_element_handler($xml, 'tag_open', 'tag_close');
// Parse!
if (!xml_parse($xml, $data, true)) {
$this->error_code = xml_get_error_code($xml);
$this->error_string = xml_error_string($this->error_code);
$return = false;
}
$this->current_line = xml_get_current_line_number($xml);
$this->current_column = xml_get_current_column_number($xml);
$this->current_byte = xml_get_current_byte_index($xml);
xml_parser_free($xml);
return $return;
}