Jump to content

Archived

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

ddeile

RSS <description> parsing issue

Recommended Posts

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.


[code]
.....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')");


}       
[/code]


The database table `feeds` is structured as follows:

[code]
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;

[/code]

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

[code]
$description = substr($item->description,0,500);
[/code]

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.

Share this post


Link to post
Share on other sites
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!!!


[code] $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 ) . "')");[/code]


me!

Share this post


Link to post
Share on other sites
Solved the issue.  Thanks printf - I would have saved myself alot of time if I had used die ( mysql_error () ). 

Share this post


Link to post
Share on other sites

×

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.