110 of 410 menu

The htmlentities Function

The htmlentities function converts characters into corresponding HTML entities. See examples for better understanding.

The function is similar to htmlspecialchars, however, unlike it, converts all characters for which an HTML entity exists.

Syntax

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

Example

Let's convert a string with tags:

<?php $str = '<b>text</b>'; $res = htmlentities($str); echo $res; ?>

Code execution result:

'<b>text</b>'

Example

Let's convert a string with an ampersand:

<?php $str = 'test: &'; $res = htmlentities($str); echo $res; ?>

Code execution result:

'test: &'

See Also

byenru