Skip to content

Instantly share code, notes, and snippets.

@AriffAzmi
Last active September 17, 2015 10:13
Show Gist options
  • Save AriffAzmi/f098dc9fe09035279cbb to your computer and use it in GitHub Desktop.
Save AriffAzmi/f098dc9fe09035279cbb to your computer and use it in GitHub Desktop.
<?php
$url = "http://admin.ariffazmi.my";
/**
*
*/
class NotUrlException extends Exception
{
}
class urlParser
{
private $url;
public function host()
{
$url = $this->url;
$host = parse_url($url, PHP_URL_HOST);
return $host;
}
public function scheme()
{
$url = $this->url;
$scheme = parse_url($url, PHP_URL_SCHEME);
return $scheme;
}
public function subdomain()
{
$url = $this->url;
$parsedUrl = parse_url($url);
$host = explode('.', $parsedUrl['host']);
$subdomain = $host[0];
return $subdomain;
}
public function validateUrl()
{
$url = $this->url;
#validate url
// $regexp = '/^[a-zA-Z0-9][a-zA-Z0-9\-\_]+[a-zA-Z0-9]$/';
// if (false === preg_match($regexp, $url)) {
// return 'Domain Invalid';
// }
if (!filter_var($url, FILTER_VALIDATE_URL) === false) {
return "$url is a valid URL";
} else {
return "$url is not a valid URL";
}
}
protected function parseUrl()
{
$url = $this->url;
}
function __construct($url)
{
$this->url = $url;
$this->validateUrl();
$this->parseUrl();
}
}
$url = new urlParser($url);
// // echo $url->host();
// echo $url->validateUrl();
// echo "<br />";
// echo $url->scheme();
// echo "<br />";
// echo $url->host();
// echo "<br />";
// echo $url->subdomain();
// echo "<br />";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment