Community « Discussion forum « Bug tracker « External news «
Comment: External news
| Next >> |
The function
Click to look at code
decode() in services/rss_codec.php has to be changed to properly deal with UTF-8 feeds, as follows:/**
* parse some news
*
* @param array the received $HTTP_RAW_POST_DATA
* @return array a status code (TRUE is ok) and the parsing result
*/
function decode($data) {
global $context;
// create a parser with proper character encoding
$encoding = 'ISO-8859-1';
if(preg_match('/?xml .+ encoding="utf-8".*?/i', $data))
$encoding = 'UTF-8';
$parser = xml_parser_create($encoding);
// parser setup
xml_set_object($parser, $this);
xml_set_element_handler($parser, 'parse_start_element',
'parse_end_element');
xml_set_character_data_handler($parser, 'parse_cdata');
// case is meaningful
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, FALSE);
// reset parsing data
$this->current_item = array(); // item currently being parsed
$this->items = array(); // collection of parsed items
$this->channel = array(); // hash of channel fields
$this->textinput = array();
$this->image = array();
$this->elements_stack = array('rss_stream');
$this->current_field = '';
$this->current_name_space = false;
// parse data
if(!xml_parse($parser, $data)) {
return array(FALSE, 'Parsing error:
'.xml_error_string(xml_get_error_code($parser))
.' at line '.xml_get_current_line_number($parser));
}
xml_parser_free($parser);
// transcode from utf8 to unicode
if($encoding == 'UTF-8')
$this->items = utf8::decode_recursively($this->items);
// return parsing result
return array(TRUE, $this->items);
}
by Bernard on Sep. 30 2006
