Thats amazing, thank you so much. What I will have to do is to tell my users to set site:example.com first then put the query. To make it easier.
So, to get the query. Ive done this...
$search = explode(' ', $string);
echo $search[1];
It works but is pretty rudimentary, would you recomend something better?
Yes, using the explode function would be the best way to get all of the keywords but in your example, you have got the site:example.com as a keyword below is how I would do it.
$string='test site:example.com site:test.com test2';
if (preg_match('/site:/i',$string))
{
preg_match_all('/site:[^ ]+/i',$string,$site);
for ($ii=0;isset($site[0][$ii]);$ii++)
{
$site[0][$ii]=strtolower(substr($site[0][$ii],5,strlen($site[0][$ii])));
}
$sites=$site[0]; unset($site);
}
$search=explode(' ',preg_replace('/[\h]+/',' ',preg_replace('/site:[^\h]+/i','',$string)));
//now to display
echo "<b>Sites</b><br>";
foreach ($sites AS $siteval)
{
echo $siteval."<br>";
}
echo "<br><b>Keywords</b>";
foreach ($search AS $val)
{
echo "<br>".$val;
}
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
Offline 3,004 posts
since Sep 2007