PHP code example of horde / url

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

    

horde / url example snippets


use Horde\Url\Url;

// Create URL
$url = new Url('https://example.com/page');

// Add parameters
$url->add(['foo' => 'bar', 'id' => 42]);
// Result: https://example.com/page?foo=bar&amp;id=42

// Set anchor
$url->setAnchor('section');
// Result: https://example.com/page?foo=bar&amp;id=42#section

// Generate HTML link
echo $url->link(['class' => 'button']);
// Output: <a href="https://example.com/page?foo=bar&amp;id=42#section" class="button">

use Horde\Url\Psr7Bridge;

// Horde Url → PSR-7 Uri
$hordeUrl = new Url('https://api.example.com/users?active=1');
$psr7Uri = Psr7Bridge::toPsr7($hordeUrl);

// PSR-7 Uri → Horde Url
$hordeUrl = Psr7Bridge::fromPsr7($psr7Uri);