\Greg\Support\Url is working with URLs.
const UA = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';- hasSchema - Determine if an URL has schema;
- noSchema - Get an URL without schema;
- schema - Set current schema to an URL;
- shorted - Set short schema to an URL;
- secured - Set secured schema to an URL;
- unsecured - Set unsecured schema to an URL;
- schemly - Add current schema to an URL if was not defined;
- shortly - Set short schema to an URL if was not defined;
- securely - Set secured schema to an URL if was not defined;
- unsecurely - Set unsecured schema to an URL if was not defined;
- absolute - Transform a relative URL to server absolute URL;
- relative - Transform an URL to relative URL;
- serverRelative - Transform a server absolute URL to relative URL;
- host - Get host from an URL;
- hostLevel - Get host level from an URL;
- hostEquals - Determine if two URLs are equal by their host;
- root - Get root of an URL;
- path - Remove query string of an URL;
- base - Get server base URL;
- addQuery - Add a query to an URL;
- init - Init an cURL handle for an URL;
- effective - Get effective URL of an URL;
- contents - Get contents of an URL.
Determine if an URL has schema.
hasSchema(string $absolute): boolean$absolute - The URL.
Example:
\Greg\Support\Url::hasSchema('example.com'); // result: false
\Greg\Support\Url::hasSchema('http://example.com'); // result: trueGet an URL without schema.
noSchema(string $absolute): string$absolute - The URL.
Example:
\Greg\Support\Url::noSchema('http://example.com'); // result: example.comSet current schema to an URL.
schema(string $absolute): string$absolute - The URL.
Example:
\Greg\Support\Url::schema('example.com'); // result: http://example.comSet short schema to an URL.
shorted(string $absolute): string$absolute - The URL.
Example:
\Greg\Support\Url::shorted('http://example.com/styles.css'); // result: //example.com/styles.cssSet secured schema to an URL.
secured(string $absolute): string$absolute - The URL.
Example:
\Greg\Support\Url::secured('http://example.com'); // result: https://example.comSet unsecured schema to an URL.
unsecured(string $absolute): string$absolute - The URL.
Example:
\Greg\Support\Url::unsecured('https://example.com'); // result: http://example.comAdd current schema to an URL if was not defined.
schemly(string $absolute): string$absolute - The URL.
Example:
\Greg\Support\Url::schemly('example.com'); // result: http://example.com
\Greg\Support\Url::schemly('https://example.com'); // result: https://example.comSet short schema to an URL if was not defined.
shorted(string $absolute): string$absolute - The URL.
Example:
\Greg\Support\Url::shortly('http://example.com/styles.css'); // result: //example.com/styles.cssSet secured schema to an URL if was not defined.
securely(string $absolute): string$absolute - The URL.
Example:
\Greg\Support\Url::securely('http://example.com'); // result: https://example.comSet unsecured schema to an URL if was not defined.
unsecurely(string $absolute): string$absolute - The URL.
Example:
\Greg\Support\Url::unsecurely('https://example.com'); // result: http://example.comTransform a relative URL to server absolute URL.
absolute(string $relative): string$relative - The URL.
Example:
// Let say server url is localhost
\Greg\Support\Url::absolute('/foo'); // result: http://localhost/fooTransform an absolute URL to relative URL.
relative(string $absolute): string$absolute - The URL.
Example:
\Greg\Support\Url::relative('http://example.com/foo'); // result: /fooTransform a server absolute URL to relative URL.
serverRelative(string $absolute): string$absolute - The URL.
Example:
// Let say server url is localhost
\Greg\Support\Url::serverRelative('http://example.com/foo'); // result: http://example.com/foo
\Greg\Support\Url::serverRelative('http://localhost/foo'); // result: /fooGet host from an URL.
host(string $absolute, boolean $stripWWW = true): string$absolute - The URL;
$stripWWW - Strip www from URL.
Example:
\Greg\Support\Url::host('http://example.com/foo'); // result: example.comGet host level from an URL.
hostLevel(string $absolute, int $level = 2, boolean $stripWWW = true): string$absolute - The URL;
$level - Host level;
$stripWWW - Strip www from URL.
Example:
\Greg\Support\Url::hostLevel('http://mobile.example.com/foo'); // result: example.com
\Greg\Support\Url::hostLevel('http://mobile.example.com/foo', 3); // result: mobile.example.comDetermine if two URLs are equal by their host.
hostEquals(string $absolute1, string $absolute2, int $level = 2): boolean$absolute1 - The first URL;
$absolute2 - The second URL;
$level - Host level.
Example:
\Greg\Support\Url::hostEquals('http://v1.example.com/foo', 'http://v2.example.com/foo'); // result: trueGet root of an URL.
root(string $absolute): string$absolute - The URL.
Example:
\Greg\Support\Url::root('http://example.com/foo'); // result: http://example.comGet without query string.
path(string $url): string$url - The URL.
Example:
\Greg\Support\Url::path('/foo?bar=BAR'); // result: /fooGet server base URL.
base(string $path = '/', boolean $absolute = false): string$path - Path;
$absolute - Return absolute URL.
Example:
// Let say your base uri is /module
\Greg\Support\Url::base('/foo'); // result: /module/fooAdd a query to an URL.
addQuery(string $url, string|array $query): string$url - URL;
$query - Query.
Example:
\Greg\Support\Url::addQuery('/?foo=FOO', ['bar' => 'BAR']); // result: /?foo=FOO&bar=BARInit an cURL handle for an URL.
init(string $absolute, boolean $verbose = false): resource$absolute - The URL;
$verbose - Verbose.
Example:
$handle = \Greg\Support\Url::init('http://example.com');
$contents = curl_exec($handle);Get effective URL of an URL.
effective(string $absolute): string$absolute - The URL.
Example:
\Greg\Support\Url::effective('http://some.old.example.com'); // result: http://example.comGet contents of an URL.
contents(string $absolute): string$absolute - The URL.
Example:
\Greg\Support\Url::contents('http://example.com'); // result: contents of the url