函数名称:htmlentities() 适用版本:所有版本 函数介绍:htmlentities() 函数将字符串中的特殊字符转换为HTML实体。它可以防止在HTML文档中出现特殊字符造成的错误或安全问...
函数名称:htmlentities()
适用版本:所有版本
函数介绍:htmlentities() 函数将字符串中的特殊字符转换为HTML实体。它可以防止在HTML文档中出现特殊字符造成的错误或安全问题。
语法:htmlentities(string $string, int $flags = ENT_COMPAT | ENT_HTML401, string|null $encoding = null, bool $double_encode = true): string
参数:
返回值:返回转换后的字符串。
示例:
$input = "I'm a <strong>PHP</strong> developer!";
$output = htmlentities($input);
echo $output;
// 输出:I'm a <strong>PHP</strong> developer!
$input = "I'm a <strong>PHP</strong> developer!";
$output = htmlentities($input, ENT_QUOTES);
echo $output;
// 输出:I'm a <strong>PHP</strong> developer!
$input = "I'm a <strong>PHP</strong> developer!";
$output = htmlentities($input, ENT_QUOTES, 'UTF-8');
echo $output;
// 输出:I'm a <strong>PHP</strong> developer!
$input = "I'm a <strong>PHP</strong> developer!";
$output = htmlentities($input, ENT_QUOTES, 'UTF-8', false);
echo $output;
// 输出:I'm a <strong>PHP</strong> developer!
注意事项: