HS Banner
Back
PHP htmlentities

Author: Brian Henry 03/17/2021
Language: PHP
Views: 91
Tags: php


Description:

htmlentities — Convert all applicable characters to HTML entities

Article:

htmlentities ( string $string , int $flags = ENT_COMPAT , string|null $encoding = null , bool $double_encode = true ) : string

This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

If you want to decode instead (the reverse) you can use html_entity_decode().

PHP: htmlentities - Manual

Full Source Code:
<?php
//Example #1 A htmlentities() example
$str = "A 'quote' is <b>bold</b>";

// Outputs: A 'quote' is <b>bold</b>
echo htmlentities($str);

// Outputs: A 'quote' is <b>bold</b>
echo htmlentities($str, ENT_QUOTES);
?>

<?php
//Example #2 Usage of ENT_IGNORE
$str = "\x8F!!!";

// Outputs an empty string
echo htmlentities($str, ENT_QUOTES, "UTF-8");

// Outputs "!!!"
echo htmlentities($str, ENT_QUOTES | ENT_IGNORE, "UTF-8");
?>

Back
Comments
Add Comment
There are no comments yet.