I hope someone has time to help with a regular expression?
I need a regex that will replace get variables, regardless of there location
in a URL, and if the get var does not exist I hope that it will create the
get var in the URL. Some examples
$REQUEST_URI can look like this "value1":
filename.phtml?test=value1
filename.phtml?another=value&test=value1
filename.phtml
filename.phtml?another=value
The variable $test will either exist preceded by "?" "&" or not at all.
I would like to take a value pair, put it into a function with $REQUEST_URI
and the have a new $REQUEST_URI returned with either the value replaced or
added.
Replacing/adding "value2"
filename.phtml?test=value2
filename.phtml?another=value&test=value2
filename.phtml?test=value2
filename.phtml?another=value&test=value2
The variable located by matching ?test &test or adding it if it does not
exist, with a "?" or a "&"
I currently have a function:
replace_get_var_value($string, $var, $new_value){
return eregi_replace("&$var=([a-z0-9\+]+)", "&$var=$new_value", $string);
}
But it won't work if the value does not exist, or if the value is the first
variable in the set within $REQUEST_URI.
Example ($REQUEST_URI that will not work with this function)
filename.phml?another=value
filename.phml?var=old_value
filename.phml
The only $REQUEST_URI that this will work with is
filename.phtml?another=value&var=old_value
I hope my description makes sense. Thanks for any help!
-Rob Z.
http://www.zwink.net
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]