Please consider using the the latest stable version for any production code.

The Fragment component

The library provides a Fragment class to ease fragment creation and manipulation.

Creating a new object

<?php
public Fragment::__construct($content = null): void

submitted string is normalized to be RFC3986 compliant.

If the submitted value is not valid a League\Uri\Exceptions\SyntaxError exception is thrown.

Properties and methods

This URI component object only exposes the package common API.

An additional decoded method returns the component value safely decoded.

public Fragment::decoded(): ?string

Usage

<?php

use League\Uri\Components\Fragment;

$fragment = new Fragment('%E2%82%AC');
echo $fragment->getContent(); //display '%E2%82%AC'
echo $fragment->decoded(); //display '€'
echo $fragment;                    //display '%E2%82%AC'
echo $fragment->getUriComponent(); //display '#%E2%82%AC'

$new_fragment = $fragment->getContent(null);
echo $new_fragment->getContent();      //display null
echo $new_fragment;                    //display ''
echo $new_fragment->getUriComponent(); //display ''

$alt_fragment = $fragment->getContent('');
echo $alt_fragment->getContent();      //display ''
echo $alt_fragment;                    //display ''
echo $alt_fragment->getUriComponent(); //display '#'

The delimiter # is not part of the component value and must not be added.

If the submitted value is not valid a League\Uri\Exceptions\SyntaxError exception is thrown.