PHP code example of ulthon / uri

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

    

ulthon / uri example snippets


composer 

use Ulthon\URI\URI;

$url = 'https://phpreturn.com/index/a6310ae8e7c561.html?name=john&[email protected]#fragment';

$uri = URI::make($url);

// 或者

$uri = new URI($url);

use Ulthon\URI\URI;

$url = 'phpreturn.com?name=john&[email protected]';

$newUrl = URI::make($url)
    ->scheme('http') // 修改链接为: http://phpreturn.com/index/a6310ae8e7c561.html?name=john&[email protected]
    ->domain('doc.ulthon.com') // 修改链接为: http://doc.ulthon.com/index/a6310ae8e7c561.html?name=john&[email protected]
    ->url();  


use Ulthon\URI\URI;

$url = 'http://phpreturn.com?name=john&[email protected]';

$domain = URI::make($url)
    ->domain();

use Ulthon\URI\URI;

$url = 'http://phpreturn.com/dir/sub/file.php?name=john&[email protected]';

$relativeUrl = '../../hello.php';

$newUrl = URI::make($url)
    ->relative($relativeUrl) // 链接修改为: http://phpreturn.com/hello.php?name=john&[email protected]
    ->url();

$url = 'https://phpreturn.com/?utm_source=summer-mailer&utm_medium=email&utm_campaign=summer-sale';

$newUrl = URI::make($url)->remove(function ($key, $value) {
    return (bool)preg_match('#^utm_#si', $key);
})->url();