4

Consider this link from Amazon.

If you notice, each seller has this block (similar, at least):

<a href="http://www.amazon.com/shops/AN8LN2YPKS7DF/ref=olp_merch_name_2">
<img src="http://ecx.images-amazon.com/images/I/41UQmT7-XyL.jpg" width="120" alt="DataVision Computer Video" height="30" border="0" />
</a> //and other junk

I want to search this page for http://ecx.images-amazon.com/images/I/41UQmT7-XyL.jpg, which is the seller image (which I already have the link for). I just want to know if the search produced results, or not. I don't even need to know more than that. Is this possible? How can I do it using PHP?

Shorty.
  • 53
  • 1
  • 1
  • 3

3 Answers3

4

You could use strpos():

$url = "http://www.example.com/";
$html = file_get_contents($url);
if (strpos($html, "http://ecx.images-amazon.com/images/I/41UQmT7-XyL.jpg") !== false) {
  // found
} else {
  // not found
}
ldiqual
  • 15,027
  • 6
  • 48
  • 89
1

If you just want to know if a particular string is present or not, use strpos():

if (strpos($html_goes_here, 'http://ecx.blahblah.jpg') !== FALSE)) {
   ... image is present ...
}

Note the use of the strict comparison operator, as per the warnings on the linked documentation page.

Marc B
  • 348,685
  • 41
  • 398
  • 480
1

I mixed params in my comment and you wanted to know how to load the HTML of the URL:

$url = "http://rads.stackoverflow.com/amzn/click/B00519RW1U";
$html = file_get_contents($url);
$found = false !== strpos($html, 'src="http://ecx.images-amazon.com/images/I/41UQmT7-XyL.jpg"');
Marc B
  • 348,685
  • 41
  • 398
  • 480
hakre
  • 184,866
  • 48
  • 414
  • 792
  • Missing semi-colon, and why are you executing a url as a system command? ;-) – DaveRandom Aug 22 '11 at 21:34
  • Thank you. However, you really messed up the first line. Should be in quotes `""` instead of backticks, and missing the semicolon. – Shorty. Aug 22 '11 at 21:35