Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.