ebchost Posted June 4, 2012 Share Posted June 4, 2012 Earlier I reported on this forum for help in creating a rss reader Of course I have successfully solved with the help of people from the forum Now I would like to go one step further and now the problem There are several types of rss news. For Example: 1. Some types such as this one contains a part <content:encoded> that is in itself http://www.zurnal.rs/category/fudbal/feed?lang=lat 2. Some types, such as this does not include <content:encoded> the part that is in itself http://www.politika.rs/rubrike/Sport/index.1.lt.xml this is error when i try to load RSS soruce from number 2 Warning: SimpleXMLElement::xpath() [simplexmlelement.xpath]: xmlXPathEval: evaluation failed in C:\Program Files (x86)\EasyPHP-5.3.9\www\reader.php on line 37 this is line: 36 $result = $item->xpath('content:encoded'); 37 preg_match('/<img[^>]+>/', $result[0], $match); 38 $item->image = $match[0]; Here is the entire code: //assigning a rss path to variable $rss = new SimpleXMLElement( 'Link to RSS news' , null, true); //Reading RSS elements, and add values to the variable //hiar is problem about different versions of RSS source foreach($rss->xpath('channel/item') as $item){ $result = $item->xpath('content:encoded'); preg_match('/<img[^>]+>/', $result[0], $match); $item->image = $match[0]; $naslov = mysql_real_escape_string($item->title); $link = mysql_real_escape_string($item->link); $opis = mysql_real_escape_string($item->description); $slika = mysql_real_escape_string($item->image); $datum = date('Y-m-d H:m:s'); $image_object = preg_match_all('/src="(.*?)"/', $result[0], $matches); $image = str_replace( '"','',$matches[0][0]); $imagee = str_replace( 'src=','',$matches[0][0]); echo "$imagee<br><hr>"; //check whether the image is content:encoded area //if image not egsist incontent:encode part, search in the description if($imagee == ""){ $description = $item->description; $descritpion_strip = strip_tags($description); $description_trim = trim($descritpion_strip); $image_object = preg_match_all('/src="(.*?)"/', $description, $matches); $image = str_replace( '"','',$matches[0][0]); $image2 = str_replace( 'src=','',$image); echo $image2; } } If they somehow managed to distinguish version of RSS news, and I will be able to get around this error how to achieve it? PS: Hiar is result of work with rss news for now. http://sportskevesti.co/ Thanks for helping to achieve this Link to comment https://forums.phpfreaks.com/topic/263643-catching-and-evasion-of-the-error/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.