#key - search2feed
)(.*?)(?=)#';
		$REGEX_PAGES='#&start=([0-9]+)|&start=([0-9]+)#';
		$lang=strip_tags($lang);
		$URL='https://www.google.com/search?hl='.$lang.$safesearch.'&id=hp&q=';

		$page=file_curl_contents($URL.str_replace(' ','+',urlencode($query)).'&num='.$nb);

		if (!$page){return false;}
		preg_match_all($REGEX_WEB, $page, $r);
		preg_match_all($REGEX_PAGES,$page,$p);
		$p=count($p[2]);

		$content=array();
		foreach ($r[1] as $key=>$val){
			$content[$key]['description']=strip_tags($r[3][$key]);
			$content[$key]['link']=strip_tags($r[1][$key]);
			$content[$key]['title']=strip_tags($r[2][$key]);
			$content[$key]['guid']=strip_tags($r[1][$key]).'#1';
			$content[$key]['pubDate']=@date('r');

		}

		$rss=array(
			'infos'=>array(
				'type'=>'rss',
				'description'=>strip_tags($query),
				'title'=>$title,
				'link'=>$link,
				
			),
			'items'=>$content
		);

		return $rss;
		
	}
function array2feed($array=null){
	if (!$array){return false;}
	
	if (empty($array['infos']['type'])){$array['infos']['type']='rss';}else{$array['infos']['type']=strtolower($array['infos']['type']);}
	if (empty($array['infos']['description'])){$array['infos']['description']='';}
	$r="\n";$t="\t";
	$tpl=array('rss'=>array(),'atom'=>array());
	$tpl['rss']['header']=''.$r.''.$r.$t.''.$r;
	$tpl['atom']['header']=''.$r;
	$tpl['rss']['footer']=$t.''.$r;
	$tpl['atom']['footer']=''.$r;
	$tpl['rss']['content-type']='Content-Type: application/rss+xml';
	$tpl['atom']['content-type']='Content-Type: application/atom+xml;charset=utf-8';

	header($tpl[$array['infos']['type']]['content-type']);
	$feed=$tpl[$array['infos']['type']]['header'];
		//create the feed's info content
		foreach($array['infos'] as $key=>$value){
			if ($array['infos']['type']=='atom'){ // ATOM
				if ($key=='link'){$feed.=$t.$t.''.$r;}
				elseif ($key=='author'){$feed.=$t.$t.''.$value.''.$r;}
				elseif ($key=='licence'){$feed.=$t.$t.'<'.$key.' href="'.$value.'" rel="license"/>'.$r;} // in atom feed, licence is the link to the licence type
				elseif ($key!='version'&&$key!='type'){$feed.=$t.$t.'<'.$key.'>'.$value.''.$r;}
			}else{ // RSS
				if ($key!='version'&&$key!='type'){$feed.=$t.$t.'<'.$key.'>'.$value.''.$r;}
			}
		}

		//then the items content
		foreach ($array['items'] as $item){
			if ($array['infos']['type']=='atom'){ $feed.=$t.$t.$t.''.$r;}else{$feed.=$t.$t.$t.''.$r;}
				foreach($item as $key=>$value){
					if ($array['infos']['type']=='atom'){ // ATOM
						if ($key=='link'){$feed.=$t.$t.$t.$t.''.$r;}
						elseif ($key=='content'){$feed.=$t.$t.$t.$t.''.htmlspecialchars($value).''.$r;}
						else{$feed.=$t.$t.$t.$t.'<'.$key.'>'.$value.''.$r;}
					}else{ // RSS
						if ($key=='date'||$key=='pubDate'||$key=='title'||$key=='link'){$feed.=$t.$t.$t.$t.'<'.$key.'>'.htmlspecialchars($value).''.$r;}
						elseif($key=='guid'){ $feed.=$t.$t.$t.$t.''.$value.''.$r;}
						else{$feed.=$t.$t.$t.$t.'<'.$key.'>'.$r;}
					}
				}
			if ($array['infos']['type']=='atom'){ $feed.=$t.$t.$t.''.$r;}else{$feed.=$t.$t.$t.''.$r;}
		}


	$feed.=$tpl[$array['infos']['type']]['footer'];
	return $feed;
}

// récupération des parametres get

if (isset($_GET['q'])){$query=strip_tags($_GET['q']);}else{exit('pas de query');}
if (isset($_GET['title'])){$title=strip_tags($_GET['title']);}else{$title='GoogolSearch for '.$query;}
if (isset($_GET['nb'])){$nb=strip_tags($_GET['nb']);}else{$nb=20;}

echo array2feed(parse_query($query,$title,$nb));

?>