PHP code example of haukurh / uri

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

    

haukurh / uri example snippets




aukurh\Uri\Uri;

$uri = new Uri('HTTPS://[email protected]:8000/some/path?q=term#result1');

echo $uri->getScheme() . PHP_EOL; // https
echo $uri->getAuthority() . PHP_EOL; // [email protected]:8000
echo $uri->getPath() . PHP_EOL; // /some/path
echo $uri->getQuery() . PHP_EOL; // q=term
echo $uri->getFragment() . PHP_EOL; // result1

echo $uri . PHP_EOL; // https://[email protected]:8000/some/path?q=term#result1

var_dump($uri->toArray());
// array(5) {
//   ["scheme"]=>
//   string(5) "https"
//   ["authority"]=>
//   string(29) "[email protected]:8000"
//   ["path"]=>
//   string(10) "/some/path"
//   ["query"]=>
//   string(6) "q=term"
//   ["fragment"]=>
//   string(7) "result1"
// }




use Haukurh\Uri\Uri;

$relativeAnchorLink = '/public/css/main.css?v=1.3';

$uri = new Uri($relativeAnchorLink);

echo $uri; // /public/css/main.css?v=1.3

$uri->scheme = 'https';
$uri->authority = 'www.example.com';

echo $uri; // https://www.example.com/public/css/main.css?v=1.3

bash
./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/