Ryaan Posted January 24, 2008 Share Posted January 24, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87501-solved-taking-a-picture-from-another-site/ Share on other sites More sharing options...
pdkv2 Posted January 24, 2008 Share Posted January 24, 2008 Put the 20080121.gif in current directory of your script Quote Link to comment https://forums.phpfreaks.com/topic/87501-solved-taking-a-picture-from-another-site/#findComment-447569 Share on other sites More sharing options...
Ryaan Posted January 24, 2008 Author Share Posted January 24, 2008 The thing is, that every week the number changes. So I'd like it to automatically show it. Quote Link to comment https://forums.phpfreaks.com/topic/87501-solved-taking-a-picture-from-another-site/#findComment-447578 Share on other sites More sharing options...
GingerRobot Posted January 24, 2008 Share Posted January 24, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/87501-solved-taking-a-picture-from-another-site/#findComment-447590 Share on other sites More sharing options...
Ryaan Posted January 24, 2008 Author Share Posted January 24, 2008 Thank you! That solved my problem! Quote Link to comment https://forums.phpfreaks.com/topic/87501-solved-taking-a-picture-from-another-site/#findComment-448132 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.