Jump to content

[SOLVED] split string into chunks


yanisdon

Recommended Posts

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

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/53225-solved-split-string-into-chunks/
Share on other sites

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

 

<?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.

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.