PHP code example of keppler / url

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

    

keppler / url example snippets




$url =  'https://[email protected]:123/forum/questions/answered/latest?tag=networking&order=newest#top';

$scheme = Scheme::https($url);

print_r($scheme->all());

echo $scheme->getPathBag()->first(); // forum
echo $scheme->getPathBag()->last(); // latest
echo $scheme->getPathBag()->raw(); // /forum/questions/answered/latest
echo $scheme->getPathBag()->get(1); // questions
echo $scheme->getPathBag()->has(0); // true
echo $scheme->getPathBag()->has(10); // false


var_dump($scheme->getQueryBag()->first()); // ['tag' => 'networking']

etc



$url =  'ftp://user:password@host:123/path';

$ftpScheme = Scheme::ftp($url);
$builder = Builder::ftp($ftpScheme);

$builder->setHost('example.com')
    ->setPassword('hunter2')
    ->setPort(5);

print_r($builder->raw());
...
ftp://user:[email protected]:5/path/

print_r($builder->encoded());
...
ftp://user:[email protected]:5/path/to+encode/ // notice the extra +

$ftpUrl = 'ftp://user:password@host:123/path';

$ftpImmutable = new FtpImmutable($ftpUrl);

echo $ftpImmutable->raw();

$ftpBuilder = new FtpBuilder();

$ftpBuilder->setHost('host')
    ->setPassword('hunter2')
    ->setPort(987)
    ->setUser('hunter');

$ftpBuilder->getPathBag()
    ->set(0, 'path')
    ->set(1, 'new path');

echo $ftpBuilder->raw(); // ftp://hunter:hunter2@host:987/path/new path/

echo $ftpBuilder->encoded(); // ftp://hunter:hunter2@host:987/path/new+path/