Examples of...
Popular examples
Top Examples
Examples of Htmlspecialchars PHP
Htmlspecialchars PHP
The htmlspecialchars() function converts special characters to HTML entities
string htmlspecialchars ( string $string <, int $flags = ENT_COMPAT <, string $charset <, bool $double_encode = true >>> )
The translations performed are:
* "&" (ampersand) becomes "&"
* """ (double quote) becomes """ when ENT_NOQUOTES is not set.
* """ (single quote) becomes "'" only when ENT_QUOTES is set.
* "<" (less than) becomes "<"
* ">" (greater than) becomes ">"
Example of htmlspecialchars() function:
<?php
$new = htmlspecialchars("<a href="test">Test</a>", ENT_QUOTES);
echo $new;
?>
output: <a href='test'>Test</a>
Other example:
<html>
<body>
<?php
$str = "Jane & "Tarzan"";
echo htmlspecialchars($str, ENT_COMPAT);
echo "<br />";
echo htmlspecialchars($str, ENT_QUOTES);
echo "<br />";
echo htmlspecialchars($str, ENT_NOQUOTES);
?>
</body>
</html>
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>
Is this example useful?
To share this example, copy and paste this code into your website, blog or forum:
string htmlspecialchars ( string $string <, int $flags = ENT_COMPAT <, string $charset <, bool $double_encode = true >>> )
The translations performed are:
* "&" (ampersand) becomes "&"
* """ (double quote) becomes """ when ENT_NOQUOTES is not set.
* """ (single quote) becomes "'" only when ENT_QUOTES is set.
* "<" (less than) becomes "<"
* ">" (greater than) becomes ">"
Example of htmlspecialchars() function:
<?php
$new = htmlspecialchars("<a href="test">Test</a>", ENT_QUOTES);
echo $new;
?>
output: <a href='test'>Test</a>
Other example:
<html>
<body>
<?php
$str = "Jane & "Tarzan"";
echo htmlspecialchars($str, ENT_COMPAT);
echo "<br />";
echo htmlspecialchars($str, ENT_QUOTES);
echo "<br />";
echo htmlspecialchars($str, ENT_NOQUOTES);
?>
</body>
</html>
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>
Is this example useful?
To share this example, copy and paste this code into your website, blog or forum:
Comments
To leave a comment, you must register for free a> or if you are already registered log in.
Has not written any comments yet.
Has not written any comments yet.
Related examples
Htmlspecialchars_decode PHP Posted on 2011-01-15 12:35:47
The htmlspecialchars_decode() function convert special HTML entities back to characters
string htmlspecialchars_decode ( string $string )...Htmlentities PHP Posted on 2011-01-15 12:33:50
The htmlentities() function convert all applicable characters to HTML entities
string htmlentities ( string $string )
This function is id...Html_entity_decode PHP Posted on 2011-01-15 12:30:04
The html_entity_decode() function converts all HTML entities to their applicable characters.
The html_entity_decode() function is the opposi...Explode PHP Posted on 2011-01-15 12:26:14
The explode() function split a string by string into an array.
array explode ( string $delimiter , string $string )
delimiter: The bounda...Echo PHP Posted on 2011-01-15 12:22:55
The echo() function outputs one or more strings.
void echo ( string $arg1 )
arg1: The parameter to output.
Examples of echo function:
...