use League\Uri\Http; $url = Http::createFromString("https://example.com"); $queryParams = ['search' => 'example']; $newUrl = $url->withQuery(http_build_query($queryParams)); echo $newUrl; //https://example.com?search=example
use League\Uri\Http; $url = Http::createFromString("https://example.com"); $pathParams = ['category' => 'books', 'book' => '123']; $newUrl = $url->withPath('/{category}/{book}', $pathParams); echo $newUrl; //https://example.com/books/123
use League\Uri\Http; $url = Http::createFromString("https://example.com"); $newUrl = $url->withFragment('about-us'); echo $newUrl; //https://example.com#about-usIn this example, we use the `League\Uri\Http` package to create a URL with the base URL as `https://example.com`. We then define a fragment identifier as `about-us` and add it to the URL using `withFragment` function. The resulting URL is then printed out. The examples above demonstrate how to use the URL building feature in PHP using the `League\Uri` package library. This package provides a clean and consistent way of constructing and manipulating URLs in PHP.