Entry
Looking for a way to grab a page of the net and see if it contains a specefic URL. Any ideas?
Aug 18th, 2004 05:52
Brenden Dawson, John Himer,
I do something similar to this already with cURL (http://curl.haxx.se/).
cURL can be used on the command line (through PHP scripts) or with PHPs
cURL extensions (requires compiling PHP with cURL).
<example>
<?php
#pay attention to your forward slashes and 'dots' and escape accordingly
$link = "http:\/\/the\\.link\\.youre\/searching\\.for";
#the following does -not- need escaped
$url = "http://the.URL.you/will/be.searching";
$c = curl_init("$url");
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$pagesource = curl_exec($c);
curl_close($c);
$pattern = "/<a href=.+".$link.".+?>/";
if (preg_match($pattern, $pagesource)) {
echo "Found a link matching your requirements.<br>";
}
?>
</example>
The preg_match will match any opening href tag that contains the $url
you set.
eg: <a href="http://the.link.youre/searching.for"...>