osw3/uri

There is no license information available for the latest version (dev-master) of this package.

Parse and manipulate URI, URL and URN.

dev-master 2019-09-08 23:51 UTC

This package is auto-updated.

Last update: 2024-12-07 02:37:20 UTC


README

Parse and manipulate URI, URL and URN.

Install

composer require osw3/uri

Usage

new Uri(string $uri);
  • $uri (string) The URI you want to parse.

Parse URI

// use namsespace
use OSW3\Uri;

// ...

// Instanciate Uri()
$uri = new Uri("http://foo.bar/opensource/database?param=value#resource");

// ..

// Get URI parameters
print_r( $uri->parameters() );

Output methods

  • print([$type])
    Return the string of URI
$uri->print();
$uri->print('uri'); // default
$uri->print('url');
$uri->print('urn');
  • parameters()
    Return an array of all URI paramaters
$uri->parameters();
Array
(
    [original] => http://foo.bar/opensource/database?param=value#resource
    [hash] => 8055f2691c03d7ef54cbec8af205de5a
    [secured] => 
    [uri] => Array
        (
            [text] => http://foo.bar/opensource/database?param=value#resource=
            [md5] => 6c89b086480fbea32bacfd40251d7cce
            [sha1] => 901bfc28a6713be0de7c0948b031c6456bc05279
        )

    [url] => Array
        (
            [text] => http://foo.bar/opensource/database
            [md5] => 05386599aadf31b39042b64d77637a25
            [sha1] => 3f681fc482c68feb13f41654f354ec23a75844a4
        )

    [urn] => Array
        (
            [text] => foo.bar/opensource/database?param=value#resource=
            [md5] => e0c2f7057a96f7115844a3bc5eb62891
            [sha1] => 9e7d3b3bbc40810f62cbdb1e5ca9a7e8295a0215
        )

    [scheme] => http
    [protocol] => http://
    [user] => 
    [pass] => 
    [host] => foo.bar
    [registrable_domain] => foo.bar
    [subdomain] => 
    [hostname] => foo
    [tld] => bar
    [isValidDomain] => 1
    [isIp] => 
    [port] => 
    [path] => /opensource/database
    [segments] => Array
        (
            [0] => opensource
            [1] => database
        )

    [file] => 
    [dirname] => 
    [filename] => 
    [extension] => 
    [query] => param=value
    [parameters] => Array
        (
            [param] => value
        )

    [fragment] => resource
    [fragments] => Array
        (
            [resource] => 
        )

)
  • getUri()

Return the original URI (your input)

$uri->getUri();
  • getScheme() (string)

Return the URI Scheme. (e.g.: http, https)

$uri->getScheme();
  • getProtocol() (string)

Return the URI Protocol. (e.g.: http://, https://)

$uri->getProtocol();
  • getIsSecured() (bool)

Return TRUE if the transport is secured (e.g.: https).
Return FALSE if the transport is not secured (e.g.: http).

$uri->getIsSecured();
  • getUser() (null|string)

Return the username of the URI

$uri->getUser();
  • getPass() (null|string)

Return the password of the URI

$uri->getPass();
  • getHost()
$uri->getHost();
  • getPort()
$uri->getPort();
  • getPath()
$uri->getPath();
  • getSegment()
$uri->getSegment();
  • getSegments()
$uri->getSegments();
  • getQuery()
$uri->getQuery();
  • getParameter()
$uri->getParameter();
  • getParameters()
$uri->getParameters();
  • getFragment()
$uri->getFragment();
  • getFragmentsParameter()
$uri->getFragmentsParameter();
  • getFragments()
$uri->getFragments();
  • getHostname()
$uri->getHostname();
  • getSubdomain()
$uri->getSubdomain();
  • getTld()
$uri->getTld();
  • getRegistrableDomain()
$uri->getRegistrableDomain();
  • getIsValidDomain()
$uri->getIsValidDomain();
  • getIsIp()
$uri->getIsIp();

Manipulation

  • changeScheme(string $scheme)
    Change the scheme (e.g.: http to view-source).
    All valid schemes here.
$uri->changeScheme('view-source');
  • secure(bool $secure)
    If $secure is TRUE, Set ON secure transnport (e.g.: http to https)
    If $secure is FALSE, Set OFF secure transnport (e.g.: https to http)
$uri->secure(true);
  • toggleSecure()
    Toggle secure transnport
$uri->toggleSecure();
  • addUser()
    Add User name if is not defined
$uri->addUser('Bob');
  • changeUser()
    Change or Add User name
$uri->changeUser('John');
  • addPass()
    Add Password if is not defined
$uri->addPass('123456!');
  • changePass()
    Change or Add Password
$uri->changePass('l2EAS6!');
  • changeHost()
    Change Full Host
$uri->changeHost('www.google.com');
  • addSubdomain()
    Add SubDomain if is not defined
$uri->addSubdomain('app');
  • changeSubdomain()
    Change or Add SubDomain
$uri->changeSubdomain('store');
  • removeSubdomain()
    Remove SubDomain
$uri->removeSubdomain();
  • changeHostname()
    Change the Hostname
$uri->changeHostname('goo');
  • changeTld()
    Change the TLD
$uri->changeTld('gl');
  • addPort()
    Add Port if is not defined
$uri->addPort(8080);
  • changePort()
    Change or Add Port
$uri->changePort(8082);
  • addSegment()
    Add a segment
$uri->addSegment('folder_A');
  • replaceSegment()
    Replace a segment
$uri->replaceSegment(1, 'folder_C'); // Replace the N segment
$uri->replaceSegment('folder_B', 'folder_C'); // Replace the segment 'folder_B'
  • removeSegment()
    Remove a segment
$uri->removeSegment('folder_A');
  • removeSegments()
    Remove all segments
$uri->removeSegments();
  • resetSegments()
    Reset segments
$uri->resetSegments();
  • addParameter()
    Add a parameter
$uri->addParameter('p1', 'lorem ipsum');
  • replaceParameter()
    Replace a parameter
$uri->replaceParameter('p2', 42);
  • removeParameter()
    Remove a parameter
$uri->removeParameter('p2');
  • removeParameters()
    Remove all parameters
$uri->removeParameters();
  • resetParameters()
    Reset parameters
$uri->resetParameters();
  • addFragment()
    Add a fragment
$uri->addFragment('p1', 'lorem ipsum');
  • replaceFragment()
    Replace a fragment
$uri->replaceFragment('p2', 42);
  • removeFragment()
    Remove a fragment
$uri->removeFragment('p2');
  • removeFragments()
    Remove all fragments
$uri->removeFragments();
  • resetFragments()
    Reset fragments
$uri->resetFragments();