Jump to content

[SOLVED] Taking a picture from another site.


Ryaan

Recommended Posts

Hey,

 

I'd like to have something that takes a website using file_get_contents ();  and show a certain picture from the website.

 

Example, the source of the website is ..

 

 

" ...

</table>
<img class="centeredImage" src="/nothingnice/comics/20080121.gif">
<table width="100%" border="0" cellpadding="0" cellspacing="8">

... "

 

How would I get it to JUST display 20080121.gif, and none of the other junk.

 

Thanks,

Ryan.

Link to comment
Share on other sites

Regular expressions are your friend:

 

<?php
$str = '" ...

</table>
<img class="centeredImage" src="/nothingnice/comics/20080121.gif">
<table width="100%" border="0" cellpadding="0" cellspacing="8">

... "';
preg_match('|<img.*?class="centeredImage".*?src="(.*?)"|',$str,$matches);
echo $matches[1];
?>

 

This would assume that there is only one image with the class centeredImage in that page. If there's not, then you either need to find something else which identifies that particular picture, or see if you can work out how many there are with that class, and if there are always a fixed number of others before it in the page.

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.