public static function isUri($value, $mode = self::ISPK_URI_ALLOW_COMMON)
{
/**
* @todo
*/
$regex = '';
switch ($mode) {
// a common absolute URI: ftp, http or https
case self::ISPK_URI_ALLOW_COMMON:
$regex .= '&';
$regex .= '^(ftp|http|https):';
// protocol
$regex .= '(//)';
// authority-start
$regex .= '([-a-z0-9/~;:@=+$,.!*()\']+@)?';
// userinfo
$regex .= '(';
$regex .= '((?:[^\\W_]((?:[^\\W_]|-){0,61}[^\\W_])?\\.)+[a-zA-Z]{2,6}\\.?)';
// domain name
$regex .= '|';
$regex .= '([0-9]{1,3}(\\.[0-9]{1,3})?(\\.[0-9]{1,3})?(\\.[0-9]{1,3})?)';
// OR ipv4
$regex .= ')';
$regex .= '(:([0-9]*))?';
// port
$regex .= '(/((%[0-9a-f]{2}|[-_a-z0-9/~;:@=+$,.!*()\'\\&]*)*)/?)?';
// path
$regex .= '(\\?[^#]*)?';
// query
$regex .= '(#([-a-z0-9_]*))?';
// anchor (fragment)
$regex .= '$&i';
break;
case self::ISPK_URI_ALLOW_ABSOLUTE:
throw new Exception('isUri() for self::ISPK_URI_ALLOW_ABSOLUTE has not been implemented.');
break;
}
$result = preg_match($regex, $value);
if ($result === 1) {
return true;
} else {
return false;
}
}