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.

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.

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.