Jump to content

Search string delimited in another string


sandeep_from

Recommended Posts

Hi,

 

I have a string (Website referrer).

Example: http://www.google.com/search?q=MY STRING HERE&hl=tl&client=firefox-a&channel=s&rls=org.mozilla:en-US:official&hs=dXZ&start=30&sa=N

 

I need to extract the keywords searched (example in the above case: "MY STRING HERE").

 

I think I need the string between "q=" and the next appearing "&".

 

How can I do this?

 

Please help.

 

Thx

Sans

Use the function parse_url() to get the query part of the url, then use the function parse_str() to get the individual elements of the query:

<?php
$referrer = 'http://www.google.com/search?q=MY STRING HERE&hl=tl&client=firefox-a&channel=s&rls=org.mozilla:en-US:official&hs=dXZ&start=30&sa=N';
$p_url = parse_url($referrer);
parse_str($p_url,$p_query);
echo $p_query['q'];
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.