Jump to content

PHP RSS Feed Reader


stlewis

Recommended Posts

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);
...
?>

Link to comment
https://forums.phpfreaks.com/topic/92866-php-rss-feed-reader/
Share on other sites

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!!

Link to comment
https://forums.phpfreaks.com/topic/92866-php-rss-feed-reader/#findComment-476224
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.