PHP htmlspecialchars_decode() Function
Complete PHP String Reference
Definition and Usage
The htmlspecialchars_decode() function converts some predefined HTML entities to
characters.
HTML entities that will be decoded are:
- & becomes & (ampersand)
- " becomes " (double quote)
- ' becomes ' (single quote)
- < becomes < (less than)
- > becomes > (greater than)
The htmlspecialchars_decode() function is the opposite of
htmlspecialchars().
Syntax
htmlspecialchars_decode(string,quotestyle)
|
Parameter |
Description |
string |
Required. Specifies the string to decode |
quotestyle |
Optional. Specifies how to decode single and double quotes. The available quote styles
are:
- ENT_COMPAT - Default. Decodes only double quotes
- ENT_QUOTES - Decodes double and single quotes
- ENT_NOQUOTES - Does not decode any quotes
|
Example 1
<?php
$str = "Jane & 'Tarzan'";
echo htmlspecialchars_decode($str);
echo "<br />";
echo htmlspecialchars_decode($str, ENT_QUOTES);
echo "<br />";
echo htmlspecialchars_decode($str, ENT_NOQUOTES);
?>
|
The browser output of the code above will be:
Jane & 'Tarzan'
Jane & 'Tarzan'
Jane & 'Tarzan'
|
If you select "View source" in the browser window, you will see the following
HTML:
<html>
<body>
Jane & 'Tarzan'<br />
Jane & 'Tarzan'<br />
Jane & 'Tarzan'
</body>
</html>
|
Example 2
<html>
<body>
<?php
$str = "My name is Øyvind Åsane. I'm Norwegian";
echo htmlspecialchars_decode($str, ENT_QUOTES);
?>
</body>
</html>
|
The browser output of the code above will be:
My name is Øyvind Åsane. I'm Norwegian
|
If you select "View source" in the browser window, you will see the following
HTML:
<html>
<body>
My name is Øyvind Åsane. I'm Norwegian
</body>
</html>
|
Complete PHP String Reference
Learn XML with <oXygen/> XML Editor - Free Trial!
|
|
oXygen helps you learn to define,
edit, validate and transform XML documents. Supported technologies include XML Schema,
DTD, Relax NG, XSLT, XPath, XQuery, CSS.
Understand in no time how XSLT and XQuery work by using the intuitive oXygen debugger!
Do you have any XML related questions? Get free answers from the oXygen
XML forum
and from the video
demonstrations.
Download a FREE 30-day trial today!
|
|