Skip to content

Class that implements more control over an URL in PHP, like a Javascript URL class

License

Notifications You must be signed in to change notification settings

rlvendramini/url-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

url-parser

PHP Unit Version Total Downloads License Open Source Love

Class that implements more control over an URL in PHP, like a Javascript URL class

Instalation

composer require rlvendramini/url-parser

Setup

If you already have a vendor library in your project, you might have the following line. If not, just add:

require __DIR__ . '/vendor/autoload.php';

Usage

Instantiate from a string

$url = URLParser::fromString($string);

then you can get query string params

$url = URLParser::fromString('https://foo.bar/home?param=value');

$url->getParam('param'); // value

and set new params or overwrite existing ones

$url = URLParser::fromString('https://foo.bar/home?param=value');

$url->setParam('param', 'super value'); // super+value
$url->setParam(' #amazing param~', 'amazing value'); // amazing+value

$url->getParam('param'); // super+value
$url->getParam('amazing_param'); // amazing+value

and finally, you can get modified url as a string

$url = URLParser::fromString('https://foo.bar/home?param=value');

$url->setParam('param', 'super value'); // super+value
$url->setParam(' #amazing param~', 'amazing value'); // amazing+value

$url->getParam('param'); // super+value
$url->getParam('amazing_param'); // amazing+value

$url->toString() // https://foo.bar/home?param=super+value&amazing_param=amazing+value

About

Class that implements more control over an URL in PHP, like a Javascript URL class

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages