1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
---
layout: default
title: The Fragment component
---
# The Fragment component
The library provides a `Fragment` class to ease fragment creation and manipulation.
## Creating a new object
~~~php
<?php
public Fragment::__construct($content = null): void
~~~
<p class="message-notice">submitted string is normalized to be <code>RFC3986</code> compliant.</p>
<p class="message-warning">If the submitted value is not valid a <code>League\Uri\Exceptions\SyntaxError</code> exception is thrown.</p>
## Properties and methods
This URI component object only exposes the [package common API](/components/2.0/api/).
An additional `decoded` method returns the component value safely decoded.
~~~php
public Fragment::decoded(): ?string
~~~
## Usage
~~~php
<?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 '#'
~~~
<p class="message-notice">The delimiter <code>#</code> is not part of the component value and <strong>must not</strong> be added.</p>
<p class="message-warning">If the submitted value is not valid a <code>League\Uri\Exceptions\SyntaxError</code> exception is thrown.</p>
|