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 Link to comment https://forums.phpfreaks.com/topic/94289-split-url/ 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; Link to comment https://forums.phpfreaks.com/topic/94289-split-url/#findComment-482963 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 Link to comment https://forums.phpfreaks.com/topic/94289-split-url/#findComment-482969 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. :-) Link to comment https://forums.phpfreaks.com/topic/94289-split-url/#findComment-482971 Share on other sites More sharing options...
dlf1987 Posted March 4, 2008 Author Share Posted March 4, 2008 That works good. Thanks! Link to comment https://forums.phpfreaks.com/topic/94289-split-url/#findComment-482973 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? Link to comment https://forums.phpfreaks.com/topic/94289-split-url/#findComment-482977 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. Link to comment https://forums.phpfreaks.com/topic/94289-split-url/#findComment-482981 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? Link to comment https://forums.phpfreaks.com/topic/94289-split-url/#findComment-482986 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']; Link to comment https://forums.phpfreaks.com/topic/94289-split-url/#findComment-482989 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. Link to comment https://forums.phpfreaks.com/topic/94289-split-url/#findComment-483020 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.