note 28790 added to function.preg-match-all
| From: | joeldegan at rack1 dot php dot net | Date: | Thu, 23 Jan 2003 23:31:27 +0000 |
| Subject: | note 28790 added to function.preg-match-all | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-42667@lists.php.net to get a copy of this message | ||
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/
--
http://www.php.net/manual/en/function.preg-match-all.php
http://master.php.net/manage/user-notes.php?action=edit+28790
http://master.php.net/manage/user-notes.php?action=delete+28790
http://master.php.net/manage/user-notes.php?action=reject+28790