Twitter\Intents\Tweet::isHTTPURL PHP Method

isHTTPURL() public static method

Is the passed URL an absolute URL using the HTTP or HTTPS scheme?
Since: 1.0.0
public static isHTTPURL ( string $url ) : boolean
$url string URL to test
return boolean true if URL was parsed and contains a HTTP or HTTPs scheme
    public static function isHTTPURL($url)
    {
        if (!(is_string($url) && $url)) {
            return false;
        }
        try {
            $scheme = parse_url($url, PHP_URL_SCHEME);
        } catch (Exception $e) {
            return false;
        }
        if ('http' === $scheme || 'https' === $scheme) {
            return true;
        }
        return false;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Test URL tester
  *
  * @since 1.0.0
  *
  * @covers ::isHTTPURL
  * @small
  *
  * @dataProvider urlProvider
  *
  * @return void
  */
 public function testIsHTTPURL($url, $expected_validity, $message = '')
 {
     if ($expected_validity) {
         $this->assertTrue(\Twitter\Intents\Tweet::isHTTPURL($url), $message);
     } else {
         $this->assertFalse(\Twitter\Intents\Tweet::isHTTPURL($url), $message);
     }
 }