PHP htmlspecialchars Function

What is htmlspecialchars Function?

Explanation

In PHP, this function is used to convert special characters to HTML entities.

Syntax:


htmlspecialchars(string,quotestyle,character-set)

In the above syntax "string" specifies the text to decode, "quotestyle" specifies how to decode single and double quotes,"characterset" specifies the character set to be used.

Example :


<html>
<body>
<?php
$str = "Hiox & 'India'";
echo htmlspecialchars($str, ENT_COMPAT);
echo "<br />";
echo htmlspecialchars($str, ENT_QUOTES);
echo "<br />";
echo htmlspecialchars($str, ENT_NOQUOTES);
?>
</html>
</body>
Result :

Hiox & 'India'
Hiox & 'India'
Hiox & 'India'

In the above example the different quote styles are used to get the characters for the given html entities

NOTE:


Please use "View Source" to know the exact output of the function

PHP Topics


Ask Questions

Ask Question