PHP code example of jeremyelliot / urlhelper

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

    

jeremyelliot / urlhelper example snippets




$fullUrl = new UrlHelper('https://boss:[email protected]/foo/bar.php?q=any&lang=en#baz');
$partialUrl = new UrlHelper('/foo/baz?param=value');

// this string is the pattern to get the full URL
$completeUrlPattern = 'scheme.user.pass.host.port.dir.file.ext.query.fragment';

echo $fullUrl->get($completeUrlPattern);
// --> https://boss:[email protected]/foo/bar.php?q=any&lang=en#baz
echo $partialUrl->get($completeUrlPattern);
// --> /foo/baz?param=value


echo $fullUrl->get('base');
// --> https://boss:[email protected]
echo $partialUrl->get('base');
// --> (empty UrlHelper, casts to empty string)


echo $fullUrl->get('user.host.dir');
// --> //[email protected]/foo/
echo $partialUrl->get('user.host.dir');
// --> /foo/



echo $fullUrl->getContextPart();
// --> https://boss:[email protected]/foo/

echo $fullUrl->get('query');
// --> ?q=any&lang=en