Inspekt\Inspekt::isUri PHP Method

isUri() public static method

..
public static isUri ( string $value, integer $mode = self::ISPK_URI_ALLOW_COMMON ) : boolean
$value string
$mode integer
return boolean
    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;
        }
    }

Usage Example

Beispiel #1
0
 /**
  *
  */
 public function testIsUri9()
 {
     $input = 'http://news.bbc.co.uk/2/hi/middle_east/8277040.stm';
     $this->assertTrue(Inspekt::isUri($input));
 }
All Usage Examples Of Inspekt\Inspekt::isUri