dlf1987 Posted March 4, 2008 Share Posted March 4, 2008 <?php $refer = 'http://www.google.com/search?q=XBOX+360&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a'; // Google if (preg_match("/\bgoogle/", "$refer")) { $refersplit = SE_filter($refer); list($SEQ1, $SEQ2) = split('q=', $refersplit); $refersplit = SE_filter($SEQ2); list($SEQ1) = split('&', $refersplit); } echo $SEQ1; ?> The above code works and echo's $SEQ1 which is "XBOX 360", but if i have a url that looks like this... $refer = 'http://www.google.com/search?sourceid=navclient&aq=t&q=XBOX+360'; Then it echo's "t" because it pulls the first aq= instead of just q= How do i fix that? Hope this makes sense Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 4, 2008 Share Posted March 4, 2008 if you just want to grab q every time: $refer = 'http://www.google.com/search?q=XBOX+360&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a'; // Google if (preg_match("/\bgoogle/", "$refer")) { $url_parts = parse_url($refer); $url_query = $url_parts['query']; $q_vals = parse_str($url_query); } echo $q; Quote Link to comment Share on other sites More sharing options...
dlf1987 Posted March 4, 2008 Author Share Posted March 4, 2008 if you just want to grab q every time: $refer = 'http://www.google.com/search?q=XBOX+360&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a'; // Google if (preg_match("/\bgoogle/", "$refer")) { $url_parts = parse_url($refer); $url_query = $url_parts['query']; $q_vals = parse_str($url_query); } echo $q; That doesnt pull the q from $refer though... Looks like you just updated your post Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 4, 2008 Share Posted March 4, 2008 tested and working. actually, this $q_vals = parse_str($url_query); should be this: parse_str($url_query); "Looks like you just updated your post" yeah, i realized my first post was off. :-) Quote Link to comment Share on other sites More sharing options...
dlf1987 Posted March 4, 2008 Author Share Posted March 4, 2008 That works good. Thanks! Quote Link to comment Share on other sites More sharing options...
dlf1987 Posted March 4, 2008 Author Share Posted March 4, 2008 is it possible to make the "q" a different word like "keyword", but still pull the q value from the URL? Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 4, 2008 Share Posted March 4, 2008 yes. the parse_str() function loads all of the variables into memory. so every query key in the string will be in memory regardless of what it is. in our example, with the single parse_str() function, in addition to $q, you'll also have $ie, $oe, $aq, and all the rest. Quote Link to comment Share on other sites More sharing options...
dlf1987 Posted March 4, 2008 Author Share Posted March 4, 2008 yes. the parse_str() function loads all of the variables into memory. so every query key in the string will be in memory regardless of what it is. in our example, with the single parse_str() function, in addition to $q, you'll also have $ie, $oe, $aq, and all the rest. What i mean is, is it possible to say "echo $keyword", but display the values of q from the URL? Or did you just answer my question, and I'm not understanding? Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 4, 2008 Share Posted March 4, 2008 Ignore me. parse_str has had an array argument for a while now. Been a long time since I've looked at the function. What i mean is, is it possible to say "echo $keyword", but display the values of q from the URL? Or did you just answer my question, and I'm not understanding? Do this: [updated] $refer = 'http://www.google.com/search?sourceid=navclient&aq=t&q=XBOX+360'; $url = parse_url($refer); parse_str($url['query'], $queries); $keyword = $queries['q']; Quote Link to comment Share on other sites More sharing options...
dlf1987 Posted March 4, 2008 Author Share Posted March 4, 2008 That works great. Thanks guys for all the help. Quote Link to comment 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.