File: fragment.md

package info (click to toggle)
php-league-uri-src 7.5.1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,712 kB
  • sloc: php: 16,698; javascript: 127; makefile: 43; xml: 36
file content (40 lines) | stat: -rw-r--r-- 1,657 bytes parent folder | download | duplicates (2)
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
---
layout: default
title: The Fragment component
---

# The Fragment component

The `Fragment` class represents the URI fragment component. Apart from the [package common API](/components/7.0/),
the class exposes an additional `decoded` method to return the component value safely decoded.

~~~php
<?php

use League\Uri\Components\Fragment;

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

$newFragment = Fragment::new();
echo $newFragment->value();           //display null
echo $newFragment->decoded();         //display ''
echo $newFragment->toString();        //display ''
echo $newFragment->getUriComponent(); //display ''
echo $newFragment;                    //display ''

$altFragment = Fragment::fromUri('https://thephpleague.com#');
echo $altFragment->value();           //display ''
echo $altFragment->decoded();         //display ''
echo $altFragment->toString();        //display ''
echo $altFragment->getUriComponent(); //display '#'
echo $altFragment;                    //display ''
~~~

<p class="message-notice">The object can not be modified, you are required to instantiate a new object.</p>
<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>