PHP code example of ozh / http_build_url
1. Go to this page and download the library: Download ozh/http_build_url library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ozh / http_build_url example snippets
http_build_url(
string|array $url,
string|array|null $parts = [],
int $flags = HTTP_URL_REPLACE,
?array &$new_url = null
): string
// Replace parts of a URL (the default)
echo http_build_url('http://example.com/some/path?a=b', ['host' => 'example.org']);
// http://example.org/some/path?a=b
// Join a relative path, merge the query string, drop auth and fragment
echo http_build_url(
'http://[email protected] /pub/index.php?a=b#files',
[
'scheme' => 'ftp',
'host' => 'ftp.example.com',
'path' => 'files/current/',
'query' => 'a=c',
],
HTTP_URL_STRIP_AUTH | HTTP_URL_JOIN_PATH | HTTP_URL_JOIN_QUERY | HTTP_URL_STRIP_FRAGMENT
);
// ftp://ftp.example.com/pub/files/current/?a=c
// Get the composed parts back
http_build_url('http://example.com/path?a=b', [], HTTP_URL_STRIP_QUERY, $parts);
// $parts === ['scheme' => 'http', 'host' => 'example.com', 'path' => '/path']
use Uri\Rfc3986\Uri;
echo Uri::parse('https://example.com/search?q=php#top')
->withPath('/docs')
->withQuery('page=2')
->withFragment(null)
->toString();
// https://example.com/docs?page=2