regex to eliminate port number from url |
I tried this and some other things. What I need in this example would be to return just localhost without the colon and the port number. There may or may not be a port number and it needs to return a value in both cases. Currently it returns 'localhost:8080' in [1][0] but I want just 'localhost' to be in there.
Code: $subject1 = "localhost:8080";
If you just want to remove the port number from the URL i would do this
$pattern = "/:[0-9]*/"; $url = preg_replace($pattern, '', $subject1); even if $subject1 = localhost:8080/index.php it will correctly return localhost/index.php
On the package it said needs Windows 7 or better. So I installed Linux.
Technically, this is a valid URL:
http://username:[email protected]=:40#:yes So you are better off parsing it with PHP's parse_url function: PHP Code: <?php |
Welcome Guest, Not a member yet? Register Sign In |