i would vote for parse_url and then throw an exception if any other element than host and port are set. the current code would convert https://test to http://https://test . i prefer to be explicit over silently trying to do something meaningful.