so, I have a calendar script that has next and previous buttons.
I have dealt with how to generate the appropriate links for next and previous, but I want to include other GET data that may be in the address. In other words:
Say I request the URI and after a bit of work, I get the following:
page=blah2&month=January&color=red
I want to remove the month variable as such:
page=blah2&color=red
which will then allow me to add the correct month for the "next month" link to the end.
the method should also remove year= and day=
So, anyone have an idea of a nice way to do this?
Help with String (URI )Parsing
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Help with String (URI )Parsing
You can access this data from the superglobal array $_GET. Only take the values you want from the array.
(#10850)
Re: Help with String (URI )Parsing
I had indeed considered that, but I do not know how many values are in the GET or what their names are.
I considered looping through the array, but I am not sure how to echo the key for each GET element.
I figured it would be easier to use some sort of regex to remove &[string1]=[string2] from the data where string1 = day, year, or month.
EDIT: This is now working. Thank you for the suggestion. It took some digging to get it right, but it does work now.
I considered looping through the array, but I am not sure how to echo the key for each GET element.
I figured it would be easier to use some sort of regex to remove &[string1]=[string2] from the data where string1 = day, year, or month.
EDIT: This is now working. Thank you for the suggestion. It took some digging to get it right, but it does work now.
-
Phoenixheart
- Forum Contributor
- Posts: 123
- Joined: Tue Nov 16, 2004 7:46 am
- Contact:
Re: Help with String (URI )Parsing
$_GET is an associative array, just like normal ones.
I'll do like this:
I'll do like this:
Code: Select all
foreach ($_GET as $key => $value)
{
if (!in_array($key, $known_keys))
{
unset($_GET[$key]);
}
}
Re: Help with String (URI )Parsing
PHOENIXHEART, thank you.
I have it working now, but that's a good, efficient way to do it! I will definitely keep that in mind for future reference.
-OmniUni
I have it working now, but that's a good, efficient way to do it! I will definitely keep that in mind for future reference.
-OmniUni