Jump to content


Photo

RSS <description> parsing issue


  • Please log in to reply
2 replies to this topic

#1 ddeile

ddeile
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 October 2006 - 12:17 AM

Hi,

I've been working on a personal aggreagator project using php5's simpleXml api.  Everything is working as expected except on one feed that I am parsing and entering into my database.  The data in the <description> tags is not being sent to the database, nor am getting any mysql or php errors.  Addionally, I can send the data in the <description> tags to the screen with no issues.



Below is simplified version of my existing code. This works fine for any rss 2.0 feed that I have tried to parse.  All except for feeds from engadet.com.


.....after connecting to database.....

$thisXml = simplexml_load_file("http://hdtv.engadget.com/rss.xml");
        foreach($thisXml->channel->item as $item)
		{
		    
			$date = date('Y-m-d h:i:s', strtotime($item->pubDate));
			
			$query = mysql_db_query('feeds', "INSERT into feed_content (title, link, description, date) VALUES( '$item->title', '$item->link', '$item->description', '$date')");
			
		
		}        


The database table `feeds` is structured as follows:

CREATE TABLE `feeds`.`feed_content` (
`id` int( 11 ) NOT NULL AUTO_INCREMENT ,
`title` varchar( 255 ) NOT NULL ,
`link` varchar( 255 ) NOT NULL ,
`description` text NOT NULL ,
`date` datetime NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = InnoDB DEFAULT CHARSET = latin1;


What is interesting is that if I shorten $item->description by:

$description = substr($item->description,0,500);

the data gets inserted into the table. But I wan't the entire <description> data inserted.

Any idea what is going on?  Again, I am not receiving any errors when this runs.

#2 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 14 October 2006 - 02:23 AM

Your not escaping the insert! Always use die ( mysql_error () );, at least until you know you have it working right! Also always escape any insert you your self are not inserting!!!


$query = mysql_db_query('feeds', "INSERT into feed_content (title, link, description, date) VALUES( '" . mysql_real_escape_string ( $item->title ) . "', '" . mysql_real_escape_string ( $item->link ) . "', '" . mysql_real_escape_string ( $item->description ) . "', '" . mysql_real_escape_string ( $date ) . "')");


me!

#3 ddeile

ddeile
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 October 2006 - 05:08 AM

Solved the issue.  Thanks printf - I would have saved myself alot of time if I had used die ( mysql_error () ). 




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users