Jump to content

[SOLVED] getting a url from a string


knowj

Recommended Posts

I need to retive a url in the following format frorm an xml file:

http://farm4.static.flickr.com/3028/2808182892_e33d69ed02_m.jpg

 

echo '<img src="'.$xml->entry[$i]->user->profile_image_url.'" alt="'.$xml->entry[$i]->title.'" title="'.$xml->entry[$i]->title.'"/> ';

 

<content type="html"><p><a href="http://www.flickr.com/people/4353454@N4502/">user</a> has added a photo to the pool:</p>

<p><a href="http://www.flickr.com/photos/999999@343/2808182892/" title="Sunset"><img src="http://farm4.static.flickr.com/3028/2808122892_e33d52ed02_m.jpg" width="240" height="180" alt="Sunset" /></a></p>
</content>

 

This would have to be done with a regular expression on the http:// and closing on the .jpg. I also cant work out which function willl be best to use ideally it would return the value rather than store it within an array.

 

thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/123603-solved-getting-a-url-from-a-string/
Share on other sites

Well, it will return the result as an array, but that's a non issue.The question is if there will only be one match or multiple. If on you can use preg_match, if multiple you will want to use preg_match_all()

 

$input = '<content type="html"><p><a href="http://www.flickr.com/people/4353454@N4502/">user</a> has added a photo to the pool:</p>

<p><a href="http://www.flickr.com/photos/999999@343/2808182892/" title="Sunset"><img src="http://farm4.static.flickr.com/3028/2808122892_e33d52ed02_m.jpg" width="240" height="180" alt="Sunset" /></a></p>
</content>';

preg_match('/http:\/\/[^ ]*?jpg/', $input, $matches);

$found = $matches[0];

echo $found;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.