The League of Extraordinary Packages

Our Packages:

Presented by The League of Extraordinary Packages

Getting Started

Uri

Uri Schemes

Uri manipulation

Uri Parts API

Services

Upgrading Guide

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:

<?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 '#'

If the submitted value is not a valid, an InvalidArgumentException exception is thrown.

On instantiation the submitted string is normalized using RFC3986 rules.

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

New since version 4.2

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 '€'