theniteowl
Programmer
Hi All,
Anyone have code to parse out the URI?
I need to break out the parameter values into an array I can loop through and test individually.
The page will look through the parameters for specific ones that are used to control display of the navigation menu and if not found will set default values. It then builds a new URL with the appropriate parameters and appends any additional parameters passed as well so they are not lost then it redirects to that new URL.
Essentially I intercept all requests to specific sub folders with an HTACCESS which rewrites the URL to go to the processing script above passing in the REQUEST_URI and QUERY_STRING values to the processing page.
I know how to pull off specific values from the URL so I can get the string containing all the parameters, I just need some code that will parse that string into an array where I can test each name/value.
I figure this is probably pretty easy but I am still a novice at PHP.
An example of what I need to do is this.
I pull in the parameter string that looks like this:
parm1=something&parm2=somethingelse&parm3=avalue
I need to loop through the parameter names to see if parm1 and parm2 exist. If they do then I add their name and value to a new string I am building, if they do not then I add them in with default values of 0. If the parameter name I read in is not one I am specifically looking for I add it to another string that will be appended to the end of the URL so they will be passed through.
So what I really need is either a method to split the values out into an array in name/value pairs and an example of looping and testing the values by name, or code that will work with the string directly doing the same thing and not using the array.
I could write this in Javascript or VBScript easily enough but just do not have the experience in PHP yet.
If anyone has sample code along these lines I can figure it out and adapt it to my needs. If it is simple enough and would not take too much time and you wrote out something specific to my needs I would greatly appreciate it.
This is a project I started for a local middle school web site which I am donating my time for. I have had too many interupptions and the project has sat for too long and they are anxious to get moving. I feel bad that I have held them up for so long and I even took today off of work as a vacation day just to focus on getting this ready so they can begin filling in the content.
Anyway, this is a long description for what should be a simple thing. I would appreciate any help or advice.
Thanks.
At my age I still learn something new every day, but I forget two others.
Anyone have code to parse out the URI?
I need to break out the parameter values into an array I can loop through and test individually.
The page will look through the parameters for specific ones that are used to control display of the navigation menu and if not found will set default values. It then builds a new URL with the appropriate parameters and appends any additional parameters passed as well so they are not lost then it redirects to that new URL.
Essentially I intercept all requests to specific sub folders with an HTACCESS which rewrites the URL to go to the processing script above passing in the REQUEST_URI and QUERY_STRING values to the processing page.
I know how to pull off specific values from the URL so I can get the string containing all the parameters, I just need some code that will parse that string into an array where I can test each name/value.
I figure this is probably pretty easy but I am still a novice at PHP.
An example of what I need to do is this.
I pull in the parameter string that looks like this:
parm1=something&parm2=somethingelse&parm3=avalue
I need to loop through the parameter names to see if parm1 and parm2 exist. If they do then I add their name and value to a new string I am building, if they do not then I add them in with default values of 0. If the parameter name I read in is not one I am specifically looking for I add it to another string that will be appended to the end of the URL so they will be passed through.
So what I really need is either a method to split the values out into an array in name/value pairs and an example of looping and testing the values by name, or code that will work with the string directly doing the same thing and not using the array.
I could write this in Javascript or VBScript easily enough but just do not have the experience in PHP yet.
If anyone has sample code along these lines I can figure it out and adapt it to my needs. If it is simple enough and would not take too much time and you wrote out something specific to my needs I would greatly appreciate it.
This is a project I started for a local middle school web site which I am donating my time for. I have had too many interupptions and the project has sat for too long and they are anxious to get moving. I feel bad that I have held them up for so long and I even took today off of work as a vacation day just to focus on getting this ready so they can begin filling in the content.
Anyway, this is a long description for what should be a simple thing. I would appreciate any help or advice.
Thanks.
At my age I still learn something new every day, but I forget two others.