I just saw this
article in my
RSS feeds, and was amazed at the complexity of the solution to a simple
problem. The goal was to change query strings in a URL to the new values
passed in as an associative array. If the URL didn’t have a query
string, add one using the array. Also, query strings in the original URL
not in the array shouldn’t be modified.
The provided function uses regular expression matching, multiple foreach
loops, and really makes the problem more complex than it needs to be.
$url is now http://www.example.com/page.php?p=4&show=column&style=2