How do you remove the port number from a url string? For example:
$string = "http://www.url.com:88";
or
$string = "http://www.url.net:88";
and so on.
I tried:
$string = substr($string, 0, strpos($string, ":", 0));
but that removes the first ":" and not the second.
You can use parse_url for that.
$urlParts = parse_url("http://www.url.net:88");
print_r($urlParts);
this will output:
Array
(
[scheme] => http
[host] => www.url.net
[port] => 88
)
then unset the port with unset($urlParts['port']) and glue it back together.
Also see http://php.net/manual/en/function.parse-url.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With