use League\Url\Url; $url = Url::createFromUrl('https://example.com/path/to/file.php?query=1'); echo $url->getScheme(); // outputs "https" echo $url->getHost(); // outputs "example.com" echo $url->getPath(); // outputs "/path/to/file.php" echo $url->getQuery(); // outputs "query=1"
use League\Url\Url; $url = new Url(); $url->setScheme('https') ->setHost('example.com') ->setPath('/path/to/file.php') ->setQuery('query=1'); echo $url->toString(); // outputs "https://example.com/path/to/file.php?query=1"In these examples, we have used the League\Url package library to create and manipulate URLs in PHP.