note 28790 deleted from function.preg-match-all by sniper
| From: | sniper@php.net | Date: | Tue, 30 Sep 2003 12:22:58 +0000 |
| Subject: | note 28790 deleted from function.preg-match-all by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57435@lists.php.net to get a copy of this message | ||
Note Submitter: joeldegan AT yahoo.com
----
Here is one in action, this shows checking google for the top ten results for a search query PHP
used as the example.
need to have curl installed :)
<?php
###
### google search finder
### Joel De Gan
### http://listbid.com/affil/
###
function GetCurlPage ($pageSpec) {
$agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";
$ref = "http://www.google.com";
$ch = curl_init($pageSpec);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_REFERER, $ref);
$tmp = curl_exec ($ch);
curl_close ($ch);
return $tmp;
}
// callback function
function filt($var) {
return(substr($var, 0, 4) == "http");
}
function googleresults($search){
global $main;
$GrabURL = "http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q="
.$search."&btnG=Google+Search";
$parsed = parse_url($GrabURL);
$host = $parsed[host];
$parts = explode(".", $host);
$count = count($parts);
$main = $parts[$count - 2] . "." . $parts[$count - 1];
$OpenFile = GetCurlPage($GrabURL);
preg_match_all("|href=\"?([^\"' >]+)|i", $OpenFile, $arrayoflinks);
$new = array_filter($arrayoflinks[1], "filt");
return $new;
}// end function
$new = googleresults("php");
//Listing the array
While(List(,$link) = Each($new)){
if(substr_count($link, $main)==0 && substr_count($link, "search?q")==0){
Echo "$link<Br>";
}//fi
}// wend
?>
outputs
http://www.php.net/
http://www.php.net/downloads.php
http://phpnuke.org/
http://www.phpbuilder.com/
http://php.resourceindex.com/
http://www.php.com/
http://www.zend.com/
http://www.jmbsoft.com/
http://www.php-homepage.de/
http://www.phpwizard.net/