PHP code example of mingalevme / http-build-url

1. Go to this page and download the library: Download mingalevme/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/ */

    

mingalevme / http-build-url example snippets




echo build_url('//github.com/mingalevme/http-build-url', [
    's' => 'https', // s (scheme): set scheme only if not presented
]); // https://github.com/mingalevme/http-build-url

echo build_url('http://github.com/mingalevme/http-build-url', [
    'S' => 'https', // S (SCHEME): force set scheme
]); // https://github.com/mingalevme/http-build-url

echo build_url('https://github.com/mingalevme/http-build-url', [
    'h' => 'bitbucket.org', // h (host): set host only if not presented
]); // https://github.com/mingalevme/http-build-url

echo build_url('https://github.com/mingalevme/http-build-url', [
    'H' => 'bitbucket.org', // H (HOST): force set host
]); // https://bitbucket.org/mingalevme/http-build-url

/**
 * Build an URL
 *
 * @param string|array $url Base url or parts of the url (aliases is not supported), to build from scratch use any falsy value, e.g. [], null or ''
 * @param array $replacement [optional] Associative array like parse_url() returns
 * @param array &$newUrlParts [optional] If set, it will be filled with the parts of the composed url like parse_url() would return
 * @return string The new URL string
 */
Mingalevme\HttpBuildUrl\HttpBuildUrl::build(string|array $url, array $replacement=[], array &$newUrlParts=null)

/**
 * "p" is not used to not confusing between port, path, password;
 * use fully qualified name
 */
[
    'u' => 'user',
    's' => 'scheme',
    'h' => 'host',
    'q' => 'query',
    'f' => 'fragment',
]