note 54020 deleted from function.preg-match by jacques
| From: | jacques@php.net | Date: | Tue, 21 Jun 2005 11:36:50 +0000 |
| Subject: | note 54020 deleted from function.preg-match by jacques | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-90737@lists.php.net to get a copy of this message | ||
Note Submitter: cdblog at gmail dot com
----
this example will return the similar keywords from Google Complete
<?php
/**
* @return array
* @params string
* @source http://php.clickz.cn/blog/my_php_blog/scripts
* @site http://php.clickz.cn/
*/
function GoogleComplete( $keywords = "" ) {
$buffer = "";
$similars = array();
$baseurl = "http://www.google.com/c" .
"omplete/search?hl=en&js=true&qu=" . $keywords;
$fp = fopen( $baseurl , "r" );
if ( $fp ) {
while ( !feof( $fp ) ) {
$buffer .= fgets( $fp , 128 );
}
# get the keywords and return array
if ( preg_match( "/new Array\((.*?)\)/si" , $buffer , $temp ) ) {
$similars = explode( "," , $temp[1] );
foreach ( $similars as $key => $val ) {
$similars[ $key ] = trim ( str_replace( "\"" , "" , $val )
);
}
}
}
return $similars;
}
print_r( GoogleComplete( "design" ) );
?>