stlewis Posted February 25, 2008 Share Posted February 25, 2008 Hi All! I've put together a pretty simple script for reading and displaying RSS feeds, but the trouble I'm having is that some of the characters in the resulting feeds come out all garbled...I figure its a problem with encoding, (I've explicitly set it to UTF-8 in my code), but I have no idea what the solution might be. Relevant code posted below for your review: <?php function Read($feed) { global $items; $parser = xml_parser_create("UTF-8"); // Set the functions to handle opening and closing tags xml_set_element_handler($parser, "startTag", "endTag"); // Set the function to handle blocks of character data xml_set_character_data_handler($parser, "characterData"); $data = file_get_contents($feed); xml_parse($parser, $data, true); xml_parser_free($parser); ... ?> Quote Link to comment Share on other sites More sharing options...
aschk Posted February 25, 2008 Share Posted February 25, 2008 Is you html meta tag encoding set to UTF-8 ? Also, consider using simpleXMLElement instead of xml_parser_create. Quote Link to comment Share on other sites More sharing options...
stlewis Posted February 25, 2008 Author Share Posted February 25, 2008 Good call on the html meta tag, that fixed the problem :-). I kinda figured it was going to be a simple gotcha like that. As for using simpleXMLElement...As soon as my hosting flips over to PHP 5, I'll definitely give it a shot...Looks a heck of a lot simpler than xml_parser... Thanks!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.