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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.