Possible duplicate:
Change the value of one variable in querystring
I found this function to add or update a parameter to a given URL, it works when the parameter needs to be added, but if the parameter exists, it does not replace it - sorry, I donβt know much about regular expression, can someone please look :
function addURLParameter ($url, $paramName, $paramValue) { // first check whether the parameter is already // defined in the URL so that we can just update // the value if that the case. if (preg_match('/[?&]('.$paramName.')=[^&]*/', $url)) { // parameter is already defined in the URL, so // replace the parameter value, rather than // append it to the end. $url = preg_replace('/([?&]'.$paramName.')=[^&]*/', '$1='.$paramValue, $url) ; } else { // can simply append to the end of the URL, once // we know whether this is the only parameter in // there or not. $url .= strpos($url, '?') ? '&' : '?'; $url .= $paramName . '=' . $paramValue; } return $url ; }
here is an example of what doesn't work:
http:
if I call addURLParameter with l = english, I get
http:
early.
php regex
Sherif Buzz Nov 04 '10 at 19:35 2010-11-04 19:35
source share