PHP code example of projectcleverweb / php-uri

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

    

projectcleverweb / php-uri example snippets


$uri = new uri('http://example.com/path/to/file.ext');

$uri->replace('QUERY', 'number=3');
$uri->replace('PATH', '/foo/bar');
$uri->append('PATH', '.baz');
$new = $uri->prepend('HOST', 'www.');

$uri->reset();
$original = $uri->str();

$uri->replace('FRAGMENT', 'Checkout');
$secure = $uri->replace('SCHEME_NAME', 'https');

echo $new.PHP_EOL;
echo $original.PHP_EOL;
echo $secure;

$uri1 = new uri('ftp://jdoe:[email protected]/public_html');

// Lets upgrade to an admin account under sftp, but stay in the current directory.
$uri1->chain()->
	prepend('SCHEME_NAME', 's')->
	replace('PORT', '22')->
	replace('USER', 'admin')->
	replace('PASS', 'secure-pass-123');

// NOTE: chain() methods always return the chain object, even if a method fails.
echo $uri1;

// Any failure results in the chain() error count geting incremented.
if (0 < $uri->chain()->error_count) {
	print_f('The chain failed %1$s times!', $uri->chain()->error_count);
}

$uri = new uri('http://example.com/path/to/file.ext?q=1');

if ($uri->scheme_name == 'https') {
	echo 'Uses SSL'.PHP_EOL;
} else {
	echo 'Does not use SSL'.PHP_EOL;
}

// Change to an absolute path
$abs_path = $_SERVER['DOCUMENT_ROOT'].$uri->path;
echo $abs_path.PHP_EOL;

// easier to read links
printf('<a href="%1$s">%2$s</a>', $uri->str(), $uri->host.$uri->path);

// FTP logins
$uri = new uri('ftp://[email protected]/my/home/dir');
$login = array(
	'username' => $uri->user,
	'password' => $user_input,
	'domain'   => $uri->host,
	'path'     => $uri->path
);

$uri1 = new uri('[email protected]:ProjectCleverWeb/PHP-URI.git');
$uri2 = new uri('[email protected]');

// Publish you source to multiple services?
echo $uri1.PHP_EOL; // PHP will automatically get the current URI
echo $uri1->replace('HOST', 'gitlab.com').PHP_EOL;
echo $uri1->replace('HOST', 'bitbucket.org').PHP_EOL.PHP_EOL;

// Quick and easy email template URI
$uri2->chain()
	->replace('SCHEME', 'mailto:')
	->query_replace('subject', 'Re: [Suggestion Box]')
	->query_replace('body', 'More snickers in the break room please!')
;
printf('<a href="%1$s">%2$s</a>', $uri2, $uri2->authority);
json
"ojectcleverweb/php-uri":"~1.0"
}