yanisdon Posted May 28, 2007 Share Posted May 28, 2007 Hello, Hope you can get me going with this: I've got the following URL: http://mysite.com/abc/xsl/search?q=dc.date.lastmodified:%5b2007-05-01T00:00:00Z%20TO%202007-05-19T00:00:00Z%5d&user=username&sr=resource&type=rss Now, I'd like to split that URL's query string part into chunks. parse_url gives me sopmething like this: [scheme] => http [host] => mysite.com [path] => /abc/xsl/search [query] => q=dc.date.lastmodified:%5b2007-05-01T00:00:00Z%20TO%202007-05-19T00:00:00Z%5d&user=username&sr=resource&type=rss to get the 'query'-part I could also use : $url = 'http://mysite.com/abc/xsl/search?q=dc.date.lastmodified:%5b2007-05-01T00:00:00Z%20TO%202007-05-19T00:00:00Z%5d&user=username&sr=resource&type=rss'; $q_str = parse_url($url, PHP_URL_QUERY); print $q_str; // that would give me something like this: // q=dc.date.lastmodified:%5b2007-05-01T00:00:00Z%20TO%202007-05-19T00:00:00Z%5d&user=username&sr=resource&type=rss Any ideas. Cheers Jan Quote Link to comment https://forums.phpfreaks.com/topic/53225-solved-split-string-into-chunks/ Share on other sites More sharing options...
AndyB Posted May 28, 2007 Share Posted May 28, 2007 <?php $q_str = "q=dc.date.lastmodified:%5b2007-05-01T00:00:00Z%20TO%202007-05-19T00:00:00Z%5d&user=username&sr=resource&type=rss"; $qbits = explode("&", $q_str); for ($i=0;$i<count($qbits);$i++) { echo $qbits[$i]. "<br/>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/53225-solved-split-string-into-chunks/#findComment-262990 Share on other sites More sharing options...
yanisdon Posted May 28, 2007 Author Share Posted May 28, 2007 Thanks for that. With that code snippet, I'll get this: q=dc.date.lastmodified:%5b2007-05-01T00:00:00Z%20TO%202007-05-19T00:00:00Z%5d user=username sr=resource type=rss I get that already with parse_url: //So I get all desired values using something like this: $q_str = parse_url(REQUEST_URL, PHP_URL_QUERY); // get the query string // print $q_str; parse_str(html_entity_decode($q_str), $output); // split the query string into chunks // result: // Array // ( // [q] => dc.date.lastmodified:[2007-05-01T00:00:00Z TO 2007-05-19T00:00:00Z] // [user] => username // [sr] => resource // [type] => rss // ) I was actually trying to split the query part which is this: q=dc.date.lastmodified:%5b2007-05-01T00:00:00Z%20TO%202007-05-19T00:00:00Z%5d Cheers Jan Quote Link to comment https://forums.phpfreaks.com/topic/53225-solved-split-string-into-chunks/#findComment-263088 Share on other sites More sharing options...
AndyB Posted May 28, 2007 Share Posted May 28, 2007 Thanks for that. I was actually trying to split the query part which is this: q=dc.date.lastmodified:%5b2007-05-01T00:00:00Z%20TO%202007-05-19T00:00:00Z%5d Split it ... into what? Two date/times? Quote Link to comment https://forums.phpfreaks.com/topic/53225-solved-split-string-into-chunks/#findComment-263182 Share on other sites More sharing options...
yanisdon Posted May 29, 2007 Author Share Posted May 29, 2007 Yes, that'd be great. Quote Link to comment https://forums.phpfreaks.com/topic/53225-solved-split-string-into-chunks/#findComment-263565 Share on other sites More sharing options...
AndyB Posted May 29, 2007 Share Posted May 29, 2007 <?php $q_str = "q=dc.date.lastmodified:%5b2007-05-01T00:00:00Z%20TO%202007-05-19T00:00:00Z%5d"; $q_str = str_replace(array("%5b","%20","%5d"), "|", $q_str); $qbits = explode("|", $q_str); for ($i=0;$i<count($qbits);$i++) { echo $qbits[$i]. "<br/>"; } ?> Or variants to suit your needs. Quote Link to comment https://forums.phpfreaks.com/topic/53225-solved-split-string-into-chunks/#findComment-263571 Share on other sites More sharing options...
yanisdon Posted May 29, 2007 Author Share Posted May 29, 2007 Great! That'll do. Thanks Jan Quote Link to comment https://forums.phpfreaks.com/topic/53225-solved-split-string-into-chunks/#findComment-263628 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.