ravi181229 Posted January 21, 2009 Share Posted January 21, 2009 Hi, I am trying to import a feed and read it using SimpleXMLElement. first I found that it has extra characters at the beginning and at the end, so I wrote code which removes extra characters : $link = 'http://ustream.tv/live.rss'; $rss_feed = file_get_contents($link); //$rss_feed = str_replace("utf-8", "iso-8859-1", $rss_feed); $rss_feed = substr($rss_feed, 5); $rss_feed = ltrim($rss_feed); $rss_feed = substr($rss_feed, 0, -5); $rss_feed = rtrim($rss_feed); $ustream = new SimpleXMLElement($rss_feed); $casts = $ustream->channel->item; foreach ($casts as $cast) { echo "<br>Title:".$cast->title; } but still it displays error. I need your help. Thanks, Ravi Quote Link to comment https://forums.phpfreaks.com/topic/141844-feed-import/ Share on other sites More sharing options...
Maq Posted January 21, 2009 Share Posted January 21, 2009 What do the errors say...? Quote Link to comment https://forums.phpfreaks.com/topic/141844-feed-import/#findComment-742662 Share on other sites More sharing options...
ravi181229 Posted January 21, 2009 Author Share Posted January 21, 2009 Error type: Php Warning Message: SimpleXMLElement::__construct() [function.SimpleXMLElement---construct]: Entity: line 276: parser error : Opening and ending tag mismatch: description line 268 and style Quote Link to comment https://forums.phpfreaks.com/topic/141844-feed-import/#findComment-742668 Share on other sites More sharing options...
Mark Baker Posted January 21, 2009 Share Posted January 21, 2009 And what are these characters that you're stripping out of $rss_feed before passing it to SimpleXMLElement? Quote Link to comment https://forums.phpfreaks.com/topic/141844-feed-import/#findComment-742692 Share on other sites More sharing options...
ravi181229 Posted January 21, 2009 Author Share Posted January 21, 2009 these are extra characters, like : 32a45 <?xm..........?> </rss> 0 Quote Link to comment https://forums.phpfreaks.com/topic/141844-feed-import/#findComment-742697 Share on other sites More sharing options...
Mark Baker Posted January 21, 2009 Share Posted January 21, 2009 I don't know about the 32a45 and 0 But I suspect that the <?xm..........?> and </rss> are probably pretty critical for SimpleXMLElement to work. It looks as though you're rendering the XML invalid by removing these. Quote Link to comment https://forums.phpfreaks.com/topic/141844-feed-import/#findComment-742701 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.