urmaul / url
Helper class to work with url strings.
v1.3.1
2018-02-19 08:26 UTC
Requires
- php: >=5.3
Requires (Dev)
- phpunit/phpunit: ^7.0
This package is not auto-updated.
Last update: 2024-11-09 16:42:50 UTC
README
Helper class to work with url strings.
Installing
composer require urmaul/url dev-master
Creating
use urmaul\url\Url; $url = new Url('http://urmaul.com/'); // or $url = Url::from('http://urmaul.com/');
Functions
- string absolute($baseUrl) - converts url from relative to absolute using base url.
echo Url::from('../html/')->absolute('http://urmaul.com/blog/tags/php/'); // http://urmaul.com/blog/tags/html/ echo Url::from('/blog/')->absolute('http://urmaul.com/blog/tags/php/'); // http://urmaul.com/blog/ echo Url::from('https://github.com/')->absolute('http://urmaul.com/blog/tags/php/'); // https://github.com/
- string addParam($name, $value) - adds get parameter to url.
echo Url::from('http://urmaul.com/')->addParam('foo', 'bar'); // http://urmaul.com/?foo=bar echo Url::from('http://urmaul.com/?foo=bar')->addParam('spam', 'ham'); // http://urmaul.com/?foo=bar&spam=ham echo Url::from('http://urmaul.com/?foo=bar')->addParam('foo', 'spam'); // http://urmaul.com/?foo=spam
- string addParams($addParams) - adds get parameters to url.
echo Url::from('http://urmaul.com/')->addParams(array('foo' => 'bar')); // http://urmaul.com/?foo=bar echo Url::from('http://urmaul.com/?foo=bar')->addParams(array('spam' => 'ham')); // http://urmaul.com/?foo=bar&spam=ham echo Url::from('http://urmaul.com/?foo=bar')->addParams(array('foo' => 'spam')); // http://urmaul.com/?foo=spam
- string removeParam($name, $value) - removes get parameter from url.
echo Url::from('http://urmaul.com/?foo=bar')->removeParam('foo'); // http://urmaul.com/ echo Url::from('http://urmaul.com/?foo=bar&spam=ham')->removeParam('spam'); // http://urmaul.com/?spam=ham
- string removeParams($removeParams) - removes get parameters from url.
echo Url::from('http://urmaul.com/?foo=bar')->removeParams(array('foo', 'spam')); // http://urmaul.com/ echo Url::from('http://urmaul.com/?foo=bar&spam=ham')->removeParams(array('foo', 'spam')); // http://urmaul.com/ echo Url::from('http://urmaul.com/?foo=bar&foo=spam&ham=spam')->removeParams(array('foo', 'spam')); // http://urmaul.com/?ham=spam