質問

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?

役に立ちましたか?

解決

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top