From the Command Line:
composer require romeoz/rock-url
In your composer.json:
{
"require": {
"romeoz/rock-url": "*"
}
}
use rock\url\Url;
// example URL: http://site.com/foo/?page=1
// returns relative URL
(new Url)->getRelative(); // output: /foo/?page=1
// modify URL
Url::set('https://site.com/?page=2#name')->removeFragment()->getRelative();
//output: /?page=2
Url::set('https://site.com/?page=2#name')->removeQueryParams(['page'])->getAbsolute();
//output: https://site.com/#name
###Short method modify()
Url::modify(['https://site.com/', 'foo' => 'test', '#' => 'name']);
//output: /?foo=test#name
Url::modify(['https://site.com/?foo=test#name', '!foo', '!#', '@scheme' => Url::ABS]);
//output: https://site.com/
// modify current url
Url::modify([foo' => 'test]);
//output: /?foo=test
- PHP 5.4+
- For generating CSRF-token (security) required Rock CSRF:
composer require romeoz/rock-csrf
All unbolded dependencies is optional
Rock URL library is open-sourced software licensed under the MIT license.