PHP code example of niladam / uri
1. Go to this page and download the library: Download niladam/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/ */
niladam / uri example snippets
use Niladam\Uri\Uri;
$uri = Uri::of('https://user:[email protected] :8080/some/subfolder?view=full#section');
// Access URI components
$scheme = $uri->scheme(); // "https"
$user = $uri->user(); // "user"
$password = $uri->password(); // "password"
$host = $uri->host(); // "example.com"
$port = $uri->port(); // 8080
$path = $uri->path(); // "some/subfolder"
$query = $uri->query()->all(); // ['view' => 'full']
$fragment = $uri->fragment(); // "section"
// String representation of the URI
echo (string)$uri; // "https://user:[email protected] :8080/some/subfolder?view=full#section"
$uri = Uri::of()
->withScheme('https')
->withHost('example.com')
->withUser('john', 'password')
->withPort(1234)
->withPath('/account/profile')
->withFragment('overview')
->replaceQuery(['view' => 'detailed']);
echo (string)$uri; // "https://john:[email protected] :1234/account/profile?view=detailed#overview"
$uri = Uri::of('https://example.com?name=Taylor&tags=php&tags=laravel&flagged');
// Access all query parameters
$query = $uri->query()->all();
// [
// 'name' => 'Taylor',
// 'tags' => ['php', 'laravel'],
// 'flagged' => ''
// ]
// Merging Queries
$uri = $uri->withQuery(['tags' => 'framework', 'new' => 'value']);
// Query: "tags=php&tags=laravel&tags=framework&new=value"
// Replacing Queries
$uri = $uri->replaceQuery(['key' => 'value']);
// Query: "key=value"
// Removing Query Keys
$uri = $uri->withoutQuery(['tags', 'new']);
// Query: "key=value"
// Pushing Values onto a Query Key
$uri = $uri->pushOntoQuery('tags', 'newTag');
// Query: "tags=php&tags=laravel&tags=newTag"
$decodedUri = $uri->decode();
// Converts encoded URI components to their decoded equivalents