将 HTML 实体转换为字符:
<?php
$str = '<a href="https://www.91xjr.com">91xjr.com</a>';
echo html_entity_decode($str);
?>
上述代码的 HTML 输出将是(查看源代码):
<a href="https://www.91xjr.com">91xjr.com</a>
上述代码的浏览器输出将是:
html_entity_decode() 函数将 HTML 实体转换为字符。
html_entity_decode() 函数与html实体()。
html_entity_decode(
string,flags,character-set)
Parameter | Description |
---|---|
string | Required. Specifies the string to decode |
flags | Optional. Specifies how to handle quotes and which document type to use. The available quote styles are:
Additional flags for specifying the used doctype:
|
character-set | Optional. A string that specifies which character-set to use. Allowed values are:
Note: Unrecognized character-sets will be ignored and replaced by ISO-8859-1 in versions prior to PHP 5.4. As of PHP 5.4, it will be ignored an replaced by UTF-8. |
返回值: | 返回转换后的字符串 |
---|---|
PHP 版本: | 4.3.0+ |
变更日志: | PHP 5.6 - 更改了默认值字符集参数为默认字符集的值(在配置中)。 PHP 5.4 - 更改了默认值字符集参数为 UTF-8。 PHP 5.4 - 添加了 ENT_HTML401、ENT_HTML5、ENT_XML1 和 ENT_XHTML。 PHP 5.0 - 添加了对多字节编码的支持 |
将一些 HTML 实体转换为字符:
<?php
$str = "Albert Einstein said: 'E=MC²'";
echo html_entity_decode($str, ENT_COMPAT); // Will only convert double quotes
echo "<br>";
echo html_entity_decode($str, ENT_QUOTES); // Converts double and single quotes
echo "<br>";
echo html_entity_decode($str, ENT_NOQUOTES); // Does not convert any quotes
?>
上述代码的 HTML 输出将是(查看源代码):
Albert Einstein said: 'E=MC²'<br>
Albert Einstein said: 'E=MC²'<br>
Albert Einstein said: 'E=MC²'
上述代码的浏览器输出将是:
Albert Einstein said: 'E=MC²'
Albert Einstein said: 'E=MC²'
Albert Einstein said: 'E=MC²'
使用西欧字符集将一些 HTML 实体转换为字符:
<?php
$str = "My name is Øyvind Åsane. I'm Norwegian.";
echo html_entity_decode($str, ENT_QUOTES, "UTF-8");
?>
上述代码的 HTML 输出将是(查看源代码):
My name is Øyvind Åsane. I'm Norwegian.
上述代码的浏览器输出将是:
My name is Øyvind Åsane. I'm Norwegian.
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!