Welcome Guest, Not a member yet? Register   Sign In
regex to eliminate port number from url
#1

(This post was last modified: 06-14-2017, 07:48 PM by cupboy1.)

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";
$subject2 = "localhost";

$pattern = "/(.*)\:{0,1}(.*)/";

$retval = preg_match($pattern, $subject1, $matches, PREG_OFFSET_CAPTURE);
Reply


Messages In This Thread
regex to eliminate port number from url - by cupboy1 - 06-14-2017, 07:45 PM



Theme © iAndrew 2016 - Forum software by © MyBB