The Fragment component
The library provides a Fragment
class to ease fragment creation and manipulation.
Instantiation
Using the default constructor.
<?php
public function __contruct($fragment = null)
The constructor accepts:
- a valid string according to their component validation rules as explain in RFC3986;
- the
null
value;
<?php
use League\Uri\Components\Fragment;
$fragment = new Fragment('eur%20o');
echo $fragment->getContent(); //display 'eur%20o'
echo $fragment; //display 'eur%20o'
echo $fragment->getUriComponent(); //display '#eur%20o'
$fragment = new Fragment();
echo $fragment->getContent(); //display null
echo $fragment; //display ''
echo $fragment->getUriComponent(); //display ''
$fragment = new Fragment('');
echo $fragment->getContent(); //display ''
echo $fragment; //display ''
echo $fragment->getUriComponent(); //display '#'
Using a League Uri object
You can acces a League\Uri\Components\Fragment
object with an already instantiated League Uri object.
<?php
use League\Uri\Fragments\Http as HttpUri;
$uri = HttpUri::createFromString('http://uri.thephpleague.com:82');
$fragment = $uri->fragment; // $fragment is a League\Uri\Components\Fragment object;
Properties
The component representation, comparison and manipulation is done using the package UriPart and the Component interfaces.
Fragment::getDecoded
Returns the decoded value of a fragment component
<?php
public Fragment::getDecoded(void): null|string
Example
<?php
use League\Uri\Components\Fragment;
$component = new Fragment('%E2%82%AC');
echo $component->getUriComponent(); //displays '#%E2%82%AC'
echo $component->getDecoded(); //displays '€'