Created
February 2, 2018 09:26
-
-
Save kobus1998/83a85b6f4ca512c1841fd57997e68aee to your computer and use it in GitHub Desktop.
regex url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$URI = "https://msdn.microsoft.com/en-us/library/system.net.httplistener(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1"; | |
$regex = "(http[s]?:\/\/)?([^\/\s]+\/)(.*)(\?.*[\&]?)"; | |
preg_match("/$regex/", $URI, $match); | |
print_r($match); | |
/* | |
Array | |
( | |
[0] => https://msdn.microsoft.com/en-us/library/system.net.httplistener(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1 | |
[1] => https:// | |
[2] => msdn.microsoft.com/ | |
[3] => en-us/library/system.net.httplistener(v=vs.110).aspx | |
[4] => ?cs-save-lang=1&cs-lang=csharp#code-snippet-1 | |
) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment