您好,欢迎来到暴趣科技网。
搜索
您的当前位置:首页HTML字符编码JS和PHP转义

HTML字符编码JS和PHP转义

来源:暴趣科技网


这个函数,将会把'  & 等直接转换为’ (单引号) 和 &

比如 you appreciate the driver's consideration , & 就会变成 you appreciate the driver’s consideration , &

PHP 将HTML字符编码 转换到 特殊字符

PHP 默认有函数将 HTML字符编码 转换到 特殊字符

html_entity_decode (PHP 4 >= 4.3.0, PHP 5)

string html_entity_decode ( string $string [, int $flags = ENT_COMPAT | ENT_HTML401 [, string $encoding = 'UTF-8' ]] )

html_entity_decode — Convert all HTML entities to their applicable characters (转换所有的HTML字符编码到对应的特殊字符串)

注意这个函数的参数ENT_COMPAT 默认会转换双引号,不会转换单引号;

为了能够同时转换单引号和双引号,需要使用 int $flags = ENT_QUOTES

通过以下的这段PHP处理数据库中的值:

html_entity_decode($node->body, ENT_QUOTES | ENT_HTML401)

这个函数,将会把'  & 等直接转换为’ (单引号) 和 &

比如 you appreciate the driver's consideration , & 就会变成 you appreciate the driver’s consideration , &

整个流程操作

假设在HTML文本框中输入这三行内容:

you appreciate the driver's consideration , &
you appreciate the driver's consideration , &
you appreciate the driver’s consideration , &

如下图:

点击“确定”按钮后,执行JQuery Ajax Post 操作 通过PHP插入到数据库;

(...)
Read the rest of HTML字符编码JS和PHP 转义 (108 words)


© lixiphp for LixiPHP, 2013. | Permalink | No comment | Add to del.icio.us
Post tags: html, JQuery, js, MySQL, PHP, 字符编码, 转义

Feed enhanced by Better Feed from Ozh

Copyright © 2019- baoquwan.com 版权所有

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务