随笔分类 -  PHP技术

摘要:.NET: 在后台设置的中文cookie,可以先用HttpUtility.UrlEncode进行编码,在前台用JS获取cookie时用decodeURIComponent进行解码PHP:1. 详见 http://www.cnblogs.com/Byrd/archive/2011/06/23/2088358.html这种设置在IE上用没有问题,但在Firefox下中文出现乱码,借鉴.net下的解决方法对字符串进行urlencode编码2.首先PHP在用urlencode编码时要转换成utf-8再编码,然后设置cookie<?php $str = "国家主席"; $tes 阅读全文
posted @ 2011-06-24 13:07 Byrd 阅读(1176) 评论(0) 推荐(0)
摘要:在PHP中先用escape函数编码,到客户端时利用js中的unescape解码。 escape函数如下: function escape($str) { preg_match_all("/[\x80-\xff].|[\x01-\x7f]+/",$str,$r); $ar = $r[0]; foreach($ar as $k=>$v) { if(ord($v[0]) < 128) $ar[$k] = rawurlencode($v); else $ar[$k] = "%u".bin2hex(iconv("GB2312",&q 阅读全文
posted @ 2011-06-23 18:09 Byrd 阅读(1689) 评论(0) 推荐(0)