Manipulate a url string by adding GET parameters

I want to add GET parameters to URLs that may and may not contain GET parameters without repeating ? or &. Example: If I want to add category=action $url="http://www.acme.com"; // will add ?