note 54020 added to function.preg-match

From: Date: Tue, 21 Jun 2005 08:17:51 +0000
Subject: note 54020 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-90729@lists.php.net to get a copy of this message
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" ) ); ?> ---- Manual Page -- http://www.php.net/manual/en/function.preg-match.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54020 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54020&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54020&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54020&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54020&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54020&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54020&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54020&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90729) next »