Download the PHP package peterpostmann/parse_uri without Composer

On this page you can find all versions of the php package peterpostmann/parse_uri. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package parse_uri

parse_uri

Build Status

Parse a URI and return its components

This function parses a URI (RFC3986 URL, URN or Windows path) and returns an associative array containing any of the various components of the URL that are present. The values of the array elements are not URL decoded.

This function is not meant to validate the given URL, it only breaks it up into the above listed parts.

Install

Via Composer

If you dont want to use composer just copy the parse_uri.php file and include it into your project.

Why

This function extends the capabailities of parse_url. It parses rfc complient URLs and URNs and (windows) file paths (basically everything which can be passed to file functions (e.g. fopen, file_get_contents)).

Usage

use function peterpostmann\uri\parse_uri;

array parse_uri ( string uri [, int $component = -2 [, bool $convertUrlToUrn = null ]]) 

Via option the output can be reduced to the output of parse_url. Otherwise additonal components are provided:

URL

schema://user:pass@host:port/path?query#fragment

array (size=14)
  'scheme' => string 'schema' (length=6)
  'host' => string 'host' (length=4)
  'port' => string '' (length=0)
  'user' => string 'user' (length=4)
  'pass' => string 'pass' (length=4)
  'path' => string 'port/path' (length=9)
  'query' => string 'query' (length=5)
  'fragment' => string 'fragment' (length=8)
  '_protocol' => string 'schema' (length=6)
  '_userinfo' => string 'user:pass@' (length=10)
  '_authority' => string 'user:pass@host:' (length=15)
  '_document' => string 'schema://user:pass@host:port/path' (length=33)
  '_ressource' => string 'schema://user:pass@host:port/path?query' (length=39)
  '_uri' => string 'schema://user:pass@host:port/path?query#fragment' (length=48)

URI

schema:path?query#fragment

array (size=8)
  'scheme' => string 'schema' (length=6)
  'path' => string 'path' (length=4)
  'query' => string 'query' (length=5)
  'fragment' => string 'fragment' (length=8)
  '_protocol' => string 'schema' (length=6)
  '_document' => string 'schema:path' (length=11)
  '_ressource' => string 'schema:path?query' (length=17)
  '_uri' => string 'schema:path?query#fragment' (length=26)

_protocol will return

Example

parse URIs

use function peterpostmann\uri\parse_uri;

echo "# URIs (with standard components)\n\n";

var_dump(parse_uri('/path/to/file.ext', peterpostmann\uri\PARSE_URI_DEFAULT));
var_dump(parse_uri('relative/path/to/file.ext', peterpostmann\uri\PARSE_URI_DEFAULT));
var_dump(parse_uri('fileInCwd.ext', peterpostmann\uri\PARSE_URI_DEFAULT));
var_dump(parse_uri('C:/path/to/winfile.ext', peterpostmann\uri\PARSE_URI_DEFAULT));
var_dump(parse_uri('C:\path\to\winfile.ext', peterpostmann\uri\PARSE_URI_DEFAULT));
var_dump(parse_uri('\\\\smbserver\share\path\to\winfile.ext', peterpostmann\uri\PARSE_URI_DEFAULT));
var_dump(parse_uri('file:///path/to/file.ext', peterpostmann\uri\PARSE_URI_DEFAULT));
var_dump(parse_uri('http://user:[email protected]:8888/path/to/file', peterpostmann\uri\PARSE_URI_DEFAULT));
var_dump(parse_uri('news:comp.infosystems.www.servers.unix', peterpostmann\uri\PARSE_URI_DEFAULT));

echo "# URIs (with additional components)\n\n";

var_dump(parse_uri('C:\path\to\winfile.ext'));
var_dump(parse_uri('\\\\smbserver\share\path\to\winfile.ext'));
var_dump(parse_uri('file:///path/to/file.ext'));
var_dump(parse_uri('http://user:[email protected]:8888/path/to/file'));
var_dump(parse_uri('news:comp.infosystems.www.servers.unix'));

The above example will output:

patch URIs

use function peterpostmann\uri\parse_uri;
use function peterpostmann\uri\build_uri;

$uri = 'https://example.org/path/to/file?query#fragment':
$patch = [ 'path' => '/path/to/otherfile']
echo build_uri($patch + parse_uri($uri));

The above example will output:

Load References

function resolveReference($reference)
{
    $components = parse_uri($reference);

    if(!isset($components['fragment']))
        return null;

    // absolute reference
    if(isset($components['_document'])) {
        $document = $this->getLoader($components['_protocol'])->load($components['_document']);
    } else { // relative reference
        $document = $this->currentDocument();
    }

    return $this->getReference($document, $components['fragment']);
}

$components['_document'] returns the URI without the fragment. ($components['_ressource'] without fragment and query). $components['_protocol'] indicates the protocol. It usualy is the same as scheme, except for file:/// URIs. For absolute, relative and windows path, scheme is not set, but $components['_protocol'] is set to file. For URIs without schema \\example.org\path the variable is set, but empty.

Helper Functions

build_uri

The function creates a uri (string) from its components.


use function peterpostmann\uri\build_uri;

echo build_uri([
          'scheme' => 'ssh2.sftp',
          'host' => 'example.com',
          'port' => 422,
          'user' => 'user',
          'pass' => 'pass',
          'path' => '/file.php',
          'query' => 'var1=val1&var2=val2',
          'fragment' => 'anchor'
      ])."\n";

echo build_uri([
          'scheme' => 'news',
          'path' => 'comp.infosystems.www.servers.unix',
      ])."\n";

The above example will output:

convert_url2urn

The function converts php URLs which are not real URLs to URNs (what they should have been in first place).

use function peterpostmann\uri\build_uri;

echo convert_url2urn('data://text/plain;base64,SSBsb3ZlIFBIUAo=')."\n";
echo convert_url2urn('zlib://archive.zip#dir/file.txt')."\n";
echo convert_url2urn('php://stdin')."\n";

The above example will output:

If the URIs are parsed as-is, the parser will look for a host part which is not present. convert_url2urn accepts a second parameter to control the conversion:

License

The MIT License (MIT). Please see License File for more information.


All versions of parse_uri with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package peterpostmann/parse_uri contains the following files

Loading the files please wait ....