CKTIS / PHP
htmlentities()
Convert characters that have entities in the selected HTML document type to those entities.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
htmlentities(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, ?string $encoding = null, bool $double_encode = true): stringConvert characters that have entities in the selected HTML document type to those entities. With ENT_QUOTES both quote types are encoded. Set the charset explicitly and use double_encode false to preserve already recognized entities. Characters without a matching entity stay as text.
Signature
htmlentities(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, ?string $encoding = null, bool $double_encode = true): string
Example output
café & Q
café & Q
Examples
<?php
echo htmlentities("caf\u{00E9} & Q",ENT_QUOTES|ENT_HTML401,"UTF-8",false), PHP_EOL;
echo htmlentities("caf\u{00E9} & Q",ENT_QUOTES|ENT_HTML401,"UTF-8",true);
Result
café & Q café &amp; Q