English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
A função htmlentities() é usada para converter caracteres em caracteres de escape HTML
string htmlentities (string $string[, int $flags = ENT_COMPAT | ENT_HTML401 [string $encoding = ini_get("default_charset")[, bool $double_encode = true]])
Usado para converter todos os caracteres aplicáveis em entidades HTML
Retorna a string codificada.
Número de ordem | Parâmetros e descrição |
---|---|
1 | string Contém informações sobre a string de entrada |
2 | flags Opcional. Especifica como lidar com aspas, códigos inválidos e qual tipo de documento usar.Tipos de aspas disponíveis:
Código inválido:
指定使用的文档类型的附加 flags:
|
3 | encoding 它是一个可选参数,定义了转换字符时使用的编码。 允许的值:
注意:在 PHP 5.4 更早版本,无法被识别的字符集将被忽略并由 ISO-8859-1 代替。自 PHP 5.4 起,无法被识别的字符集将被忽略并由 UTF-8 代替。 |
4 | double_encode 可选。一个指定了是否编码已存在的 HTML 实体的布尔值。
|
试试下面的实例,将字符转换为 HTML 实体
<?php //将字符转换为 HTML 实体 $str = "PHP Function htmlentities"; echo htmlentities($str); echo htmlentities($str, ENT_QUOTES); ?>测试看看‹/›
输出结果-
PHP Function htmlentitiesPHP Function htmlentities