Learn how we represent URIs
This library is abandoned. Please consider using a different library.
URIs are represented with the help of the
The role of this class is to decompose an URI into its basic components and provide developerds various methods that
allow them to read the value of these individual components.
Constructing an URI is supper-easy and can be accomplished just as simple as bellow:
use Opis\Http\Uri; $uri = new Uri("http://example.com"); echo $uri->getHost(); //> example.com
An URI object can be converted back to string through a simple type casting.
use Opis\Http\Uri; $uri = new Uri('http://example.com'); // explicit type casting $value = (string) $uri; echo $value; //> http://example.com // implicit type catsing echo $uri; //> http://example.com
You can obtain an array of components by calling the
getComponents method. The method will return
a key-value mapped array where the key represents the component’s name and the value represents the component’s value.
$components = $uri->getComponents();
The following components are available for the following URI
port- 8080. When the port is not explicitly specified, the value of this components is derived from the scheme component: 80 when the scheme is http, 443 when the scheme is https, and
The components of an URI can be accessed individually by using the following methods:
getScheme- read the
getAuthority- read the
getUserInfo- read the
getHost- read the
getPort- read the
getPath- read the
getQuery- read the
getFragment- read the
You can also construct an URI by passing an array of components to its constructor.
use Opis\Http\Uri; $components = [ 'scheme' => 'https', 'host' => 'example.com', 'path' => '/test' ]; $uri = new Uri($components); echo $uri->getPort(); //> 443 echo $uri->getPath(); //> /test echo $uri; //>https://example.com/test