use League\Url\Url; $url = Url::createFromUrl('https://www.example.com/path/to/page?query=value#fragment'); echo $url->getHost(); // Outputs www.example.com echo $url->getPath(); // Outputs /path/to/page echo $url->getQuery(); // Outputs query=value
use League\Url\Url; $url = Url::createFromUrl('https://www.example.com'); $url = $url->withPath('/path/to/page')->withQuery(['param1' => 'value1', 'param2' => 'value2']); echo $url->toString(); // Outputs https://www.example.com/path/to/page?param1=value1¶m2=value2
use League\Url\Url; $url = Url::createFromUrl('https://www.example.com/search?q=php url tools'); echo $url->getEncodedQuery(); // Outputs q=php+url+tools echo $url->getQueryParameter('q'); // Outputs php url toolsIn this example, we use the `getEncodedQuery()` method to encode the query parameters of the URL and the `getQueryParameter()` method to retrieve a specific parameter and decode its value. In conclusion, PHP Url Tools is a package library that provides convenient methods for working with URLs in PHP.