Jump to content

getting rid of unwanted info


Go to solution Solved by foucquet,

Recommended Posts

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 by foucquet
Link to comment
https://forums.phpfreaks.com/topic/288898-getting-rid-of-unwanted-info/
Share on other sites

  • Solution

 

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 by foucquet
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.