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
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;

Link to comment
Share on other sites

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.