PHP code example of aura / uri

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

    

aura / uri example snippets



use Aura\Uri\Url\Factory as UrlFactory;
use Aura\Uri\PublicSuffixList;

$psl = new PublicSuffixList(


$string = 'http://anonymous:[email protected]/path/to/index.php/foo/bar.xml?baz=dib#anchor');
$url = $url_factory->newInstance($string);

// now the $url properties are ...
// 
// $url->scheme    => 'http'
// $url->user      => 'anonymous'
// $url->pass      => 'guest'
// $url->host      => Aura\Uri\Host, with these methods:
//                      ->get()                     => 'example.com'
//                      ->getSubdomain()            => null
//                      ->getRegisterableDomain()   => 'example.com'
//                      ->getPublicSuffix()         => 'com'
// $url->port      => null
// $url->path      => Aura\Uri\Path, with these ArrayObject elements:
//                      ['path', 'to', 'index.php', 'foo', 'bar']
//                    and this method:
//                      ->getFormat() => '.xml'
// $url->query     => Aura\Uri\Query, with these ArrayObject elements:
//                      ['baz' => 'dib']
// $url->fragment  => 'anchor'


$url = $url_factory->newCurrent();


// start with a full URL
$string = 'http://anonymous:[email protected]/path/to/index.php/foo/bar.xml?baz=dib#anchor';
$url = $url_factory->newInstance($string);

// change to 'https://'
$url->setScheme('https');

// remove the username and password
$url->setUser(null);
$url->setPass(null);

// change the value of 'baz' from 'dib' to 'zab'
$url->query->baz = 'zab';

// add a new query element called 'zim' with a value of 'gir'
$url->query->zim = 'gir';

// reset the path to something else entirely.
// this will additionally set the format to '.php'.
$url->path->setFromString('/something/else/entirely.php');

// add another path element
$url->path[] = 'another';

// get the url as a string; this will be without the scheme, host, port,
// user, or pass.
$new_url = $url->get();

// the $new_url string is as follows; notice how the format
// is always applied to the last path-element:
// /something/else/entirely/another.php?baz=zab&zim=gir#anchor

// get the full url string, including scheme, host, port, user, and pass.
$full_url = $url->getFull();

// the $full_url string is as follows:
// https://example.com/something/else/entirely/another.php?baz=zab&zim=gir#anchor