foucquet Posted May 31, 2014 Share Posted May 31, 2014 (edited) I am parsing an rss feed from my flickr photostream using this:- <?php $url = "http://api.flickr.com/services/feeds/photos_public.gne?id=49466419@N05&lang=en-us&format=rss_200"; $rss = simplexml_load_file($url); if($rss) { echo '<h1>'.$rss->channel->title.'</h1>'; echo '<li>'.$rss->channel->pubDate.'</li>'; $items = $rss->channel->item; foreach($items as $item) { $title = $item->title; $link = $item->link; $published_on = $item->pubDate; $description = $item->description; echo '<h3><a href="'.$link.'">'.$title.'</a></h3>'; echo '<span>('.$published_on.')</span>'; echo '<p>'.$description.'</p>'; } } ?> which gives me this as the description for each image:- public 'description' => string ' <p><a href="http://www.flickr.com/people/alfthomas/">Alf Thomas</a> posted a photo:</p> <p><a href="http://www.flickr.com/photos/alfthomas/14064465890/" title="harlaw_12"> <img src="http://farm6.staticflickr.com/5077/14064465890_83c02ecec6_m.jpg" width="240" height="110" alt="harlaw_12" /> </a> </p> <p>A view of Harlaw Reservoir.</p>' (length=338) What I actually want is the photo (linked back) without the "Alf Thomas posted a photo" bit, does anyone have any idea how I would go about cloning that bit out? Edited May 31, 2014 by foucquet Quote Link to comment https://forums.phpfreaks.com/topic/288898-getting-rid-of-unwanted-info/ Share on other sites More sharing options...
Ch0cu3r Posted May 31, 2014 Share Posted May 31, 2014 Could use regex $description = preg_replace('#<p><a[^>]+>[\w\s]+</a> posted a (photo|video):</p>#i', '', $item->description); Quote Link to comment https://forums.phpfreaks.com/topic/288898-getting-rid-of-unwanted-info/#findComment-1481482 Share on other sites More sharing options...
Solution foucquet Posted May 31, 2014 Author Solution Share Posted May 31, 2014 (edited) Could use regex $description = preg_replace('#<p><a[^>]+>[\w\s]+</a> posted a (photo|video):</p>#i', '', $item->description); Thanks, that's so obvious now that I see it. I was busy playing around with str functions and getting nowhere... Edited May 31, 2014 by foucquet Quote Link to comment https://forums.phpfreaks.com/topic/288898-getting-rid-of-unwanted-info/#findComment-1481493 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.