Mecha CMS

URL::short()

Convert full URL into relative URL.

2.0.0 Static

URL::short(string $value, bool $ground = true);
URL::short(string $value, bool $ground = true, URL $url = $GLOBALS['url']);
URL::short(string $value, string $root);

Example:

$A = URL::short('https://mecha-cms.com');
$B = URL::short('https://mecha-cms.com/foo');
$C = URL::short('https://mecha-cms.com?foo');
$D = URL::short('https://mecha-cms.com&foo');
$E = URL::short('https://mecha-cms.com#foo');
$F = URL::short('https://mecha-cms.com/foo/bar');
$G = URL::short('https://mecha-cms.com?foo&bar');
$H = URL::short('https://mecha-cms.com&foo&bar');
$I = URL::short('//mecha-cms.com');
$J = URL::short('http://example.com'); // External URL
$K = URL::short('//example.com'); // External URL with relative protocol

Result:

$A = '/';
$B = '/foo';
$C = '?foo';
$D = '&foo';
$E = '#foo';
$F = '/foo/bar';
$G = '?foo&bar';
$H = '&foo&bar';
$I = '/';
$J = 'http://example.com';
$K = '//example.com';

Note: If $ground is false, then the sub-directory path where the CMS is being installed will be removed too. The $ground parameter changes makes sense only when Mecha is installed in a sub-directory.