PHP code example of dealnews / url

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

    

dealnews / url example snippets


use DealNews\Url\Url;

$url = new Url('https://user:[email protected]:443/products/tv?q=4k#details');
$url->normalize(); // lowercases scheme/host and sorts query parameters

$url->query_string->setParameter('page', '2');
$url->fragment = 'reviews';

echo $url->build(); // https://user:[email protected]/products/tv?q=4k&page=2#reviews

// Merge additional data without losing the existing state
$combined = $url->merge('http://cdn.example.com/media', '?size=large');
// $combined => http://cdn.example.com/media?size=large
// $url remains unchanged

use DealNews\Url\QueryString;

$qs = new QueryString('foo=1&bar=2');
$qs->setParameter('foo', '3');
$qs->addParameter(null, 'feature'); // unnamed flag
$qs->sortParameters(); // only sorts when all params are named

echo $qs->build(); // foo=3&bar=2&feature

$qs = new QueryString(null, ';');
$qs->parse('token;user=john;role=admin', ';');
$qs->addParameter('expires', '1700000000');

echo $qs->build(); // token;user=john;role=admin;expires=1700000000

use DealNews\Url\Exception\Parse;
use DealNews\Url\Url;

try {
    $url = new Url();
    $url->invalid_property = 'value';
} catch (Parse $e) {
    // Handle invalid assignment
}