作者foxzgerald (O⊥M)
看板PHP
标题Re: [请益] FCKEditor写入资料时如果带有单引号时
时间Thu Feb 1 16:57:57 2007
※ 引述《Graphy (Graphy)》之铭言:
: FCKEditor单引号的问题
: FckEditor在写入资料时
: 如文字栏位里遇到有单引号『'』时
: 就会变成『'\』
: 这要怎麽解决呢?
: 我搜寻了google
: 好像很多人遇到同样的麻烦
: 但一直找不到解决方案
: 快疯了
因为引号对资料库有特殊意义,所以写入时需要将其脱序。
而自资料库读出後,则须经反脱序的方式还原内容。
有两种方式:
(1). 用 addslashes - stripslashes
(2). 或用 base64_encode - base64_decode
我喜欢用第二种,使用方法如下:
function encodeHtml($html) {
// 将 html 压缩後转成安全字串
return base64_encode(gzdeflate($html));
// return base64_encode($html); // 也可以不选择 gzdeflate
}
function decodeHtml($encoded_html) {
// 将编码过的 html 还原;怎麽编码、就照着相反的程序解码
return gzinflate(base64_decode($encoded_html));
// return base64_decode($encoded_html); //也可以不选择 gzinflate
}
// gzdeflate 和 gzinflate 分别是压缩成 gz 和解压缩 gz 的函式
PS 1:
再将 html 内容存入资料库时,先以 encodeHtml 处理;
而自资料库读出该内容时,则以 decodeHtml 还原...
PS 2:
base64_encode() returns data encoded with base64. This encoding is designed
to make binary data survive transport through transport layers that are not
8-bit clean, such as mail bodies.
--
「640K ought to be enough for anybody.!」
- Bill Gates -
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.119.199.121
1F:推 doall :n文阿好文~ 08/25 17:24