Opening Multiple Files/Links in Order.

Posted on 16th Feb 2014 by admin

I want to open links in order/one-by-one and check each for a specific string.

Example:
If i open CL, search for ads pertaining to video games. Returns 20 results. I grab these links. Now i want to open each of these links one-by-one to see if an email address is included.

As of now i am able to retrieve the links, but need to know how to parse them one-by-one to check the email address.
I will then either copy the address or immediately return back to the list of links if the address is non-existent.

So here's my current code for this process thus far.
Code: [Select] <?php
function curlURL($url) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2');
$output = curl_exec($curl);
return $output;
}

$curlResults = curlURL("http://southcoast.craigslist.org/sss/");
$pattern = '#<a href="(/[a-z]{3}/d{10}.html)">#';
preg_match_all( $pattern, $curlResults, $matches);

echo "<pre>n";
echo "Links:nn";
foreach ($matches[1] as $link):
echo "t" . '<a href="' . $link . '" target="_BLANK">' . $link . '</a>' . "n";
endforeach;
echo '</pre>';


?>

Other forums