sandeep_from Posted June 5, 2007 Share Posted June 5, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/54284-search-string-delimited-in-another-string/ Share on other sites More sharing options...
kenrbnsn Posted June 5, 2007 Share Posted June 5, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/54284-search-string-delimited-in-another-string/#findComment-268362 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.