函数名:html_entity_decode()
适用版本:PHP 4, PHP 5, PHP 7
用法:html_entity_decode() 函数将 HTML 实体转换为对应的字符。它可以处理所有被 htmlentities() 或 htmlspecialchars() 转换为实体的字符。
语法:html_entity_decode(string $string, int $flags = ENT_COMPAT | ENT_HTML401, string|null $encoding = ini_get("default_charset")): string|false
参数:
返回值:返回转换后的字符串,如果出错则返回 false。
示例:
$html = "<p>This is a <b>sample</b> text.</p>";
$decodedHtml = html_entity_decode($html);
echo $decodedHtml;
// 输出:"<p>This is a <b>sample</b> text.</p>"
在上述示例中,我们将包含 HTML 实体的字符串 $html 使用 html_entity_decode() 函数进行解码,并将解码后的结果赋值给变量 $decodedHtml。然后,我们使用 echo 输出解码后的字符串,即实体被转换为相应的字符。