Created
September 28, 2014 05:28
-
-
Save detain/957070237de928da5dc0 to your computer and use it in GitHub Desktop.
URL detection and split it into parts, each part is optional minus the hostname.
This file contains 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 | |
function is_url($text) | |
{ | |
if (preg_match('/((?P<protocol>[a-z]{3,6}):\/\/)?((?P<userpass>[a-z]+:[a-z]+|[a-z]+)@)?(?P<hostname>[a-z0-9.-]+\.[a-z]{2,6})(:(?P<port>[0-9]+))?(?P<path>\/.)?/i', $text, $matches)) | |
{ | |
$ret = array(); | |
foreach ($matches as $key => $value) | |
{ | |
if (!is_numeric($key) && $value != '') | |
{ | |
$ret[$key] = $value; | |
} | |
} | |
return $ret; | |
} | |
return false; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment