Jump to content

RSS <description> parsing issue


ddeile

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.
Link to comment
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!
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.