zoukankan      html  css  js  c++  java
  • PHP 把字符转换为 HTML 实体

    定义和用法

    htmlentities() 函数把字符转换为 HTML 实体。

    语法

    htmlentities(string,quotestyle,character-set)
    参数描述
    string 必需。规定要转换的字符串。
    quotestyle

    可选。规定如何编码单引号和双引号。

    • ENT_COMPAT - 默认。仅编码双引号。
    • ENT_QUOTES - 编码双引号和单引号。
    • ENT_NOQUOTES - 不编码任何引号。
    character-set

    可选。字符串值,规定要使用的字符集。

    • ISO-8859-1 - 默认。西欧。
    • ISO-8859-15 - 西欧(增加 Euro 符号以及法语、芬兰语字母)。
    • UTF-8 - ASCII 兼容多字节 8 比特 Unicode
    • cp866 - DOS 专用 Cyrillic 字符集
    • cp1251 - Windows 专用 Cyrillic 字符集
    • cp1252 - Windows 专用西欧字符集
    • KOI8-R - 俄语
    • GB2312 - 简体中文,国家标准字符集
    • BIG5 - 繁体中文
    • BIG5-HKSCS - Big5 香港扩展
    • Shift_JIS - 日语
    • EUC-JP - 日语

    提示和注释

    提示:无法被识别的字符集将被忽略,并由 ISO-8859-1 代替。

    例子

    <html>
    <body>
    <?php
    $str = "John & 'Adams'";
    echo htmlentities($str, ENT_COMPAT);
    echo "<br />";
    echo htmlentities($str, ENT_QUOTES);
    echo "<br />";
    echo htmlentities($str, ENT_NOQUOTES);
    ?>
    </body>
    </html>

    浏览器输出:

    John & 'Adams'
    John & 'Adams'
    John & 'Adams'

    如果在浏览器中查看源代码,会看到这些 HTML:

    <html>
    <body>
    John &amp; 'Adams'<br />
    John &amp; &#039;Adams&#039;<br />
    John &amp; 'Adams'
    </body>
    </html>
  • 相关阅读:
    scrapy 多个爬虫运行
    scrapy不抓取重复的网页解决办法
    centos7 安装mysql
    20个免费和开源数据可视化工具
    转载 CSDN 谈谈我对证券公司一些部门的理解(前、中、后台)
    scrapy 教程
    django 常见错误汇总
    python 常见错误
    python 基础知识整理
    使用SQL语法来查询Elasticsearch:Elasticsearch-SQL插件
  • 原文地址:https://www.cnblogs.com/cloudshadow/p/php_htmlentities.html
Copyright © 2011-2022 走看看