Skip to content

Instantly share code, notes, and snippets.

@szepeviktor
Created December 17, 2024 06:48

Revisions

  1. szepeviktor created this gist Dec 17, 2024.
    11 changes: 11 additions & 0 deletions build_url.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    <?php

    function build_url(string $host, array $segments = [], array $parameters = []): string
    {
    return sprintf(
    'https://%s/%s?%s',
    idn_to_ascii($host),
    implode('/', array_map('urlencode', $segments)),
    http_build_query($parameters, '', '&')
    );
    }