Question

Is there a php command to determine the default port for a given url? parse_url only seems to return the port if it is explicitly specified in the url, but my function needs to return the correct port regardless.

Examples:

parse_url('http://example.com:81') //returns port 81

parse_url('http://example.com') //doesn't have a port in the return, but I must return 80

parse_url('https://example.com') //doesn't have a port in the return, but I must return 443

I could certainly create a hardcoded mapping of schemes to ports, but is there a better way?

Was it helpful?

Solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top