PHP code example of prinx / url

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

    

prinx / url example snippets


$url = new \Prinx\Url;

$newUrl = $url->addQueryString('https://test.com', ['action' => 'test']); // https://test.com?action=test
$newUrl = $url->addQueryString('https://test.com?name=url', ['action' => 'test']); // https://test.com?name=url&action=test

$urlParts = $url->getParts('https://test.com?name=url');

/*
[
  'scheme' => 'https'
  'host'   => 'test.com'
  'path'   => '/path/'
  'query'  => 'query=string&action=test&name=url'
]
*/

$urlParts = $url->getParts('https://user:[email protected]:85/path/?action=test&name=url#faq');

/*
[
  'scheme'   =>  'https'
  'host'     =>  'test.com'
  'port'     =>  85
  'user'     =>  'user'
  'pass'     =>  'password'
  'path'     =>  '/path/'
  'query'    =>  'action=test&name=url'
  'fragment' =>  'faq'
]
*/

$queryStrings = $url->getQueryStrings('https://test.com?name=url&action=test');

// ['name' => 'url', 'action' => 'test']

$newUrl = $url->removeQueryString('https://test.com?name=url&action=test', 'name');

// https://test.com?action=test

$newUrl = $url->removeQueryString('https://test.com?name=url&action=test', ['name', 'action']);

// https://test.com