日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

如何使用PHP實(shí)現(xiàn)javascript的escape和unescape函數(shù)_PHP教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:使用PHP會話(Session)實(shí)現(xiàn)用戶登陸功能
對比起 Cookie,Session 是存儲在服務(wù)器端的會話,相對安全,并且不像 Cookie 那樣有存儲長度限制,本文簡單介紹 Session 的使用。 由于 Session 是以文本文件形式存儲在服務(wù)器端的,所以不怕客戶端修改 Session 內(nèi)容。實(shí)際上在服務(wù)器端的 Session 文件,PHP 自動修改

前端開發(fā)工程師都知道javascript有編碼函數(shù)escape()和對應(yīng)的解碼函數(shù)unescape(),而php中只有個urlencode和 urldecode,這個編碼和解碼函數(shù)對encodeURI和encodeURIComponent有效,但是對escape的是無效的。
javascript中的escape()函數(shù)和unescape()函數(shù)用戶字符串編碼,類似于PHP中的urlencode()函數(shù),下面是php實(shí)現(xiàn)的escape函數(shù)代碼

復(fù)制代碼 代碼如下:
/**
* js escape php 實(shí)現(xiàn)
* @param $string the sting want to be escaped
* @param $in_encoding
* @param $out_encoding
*/
function escape($string, $in_encoding = 'UTF-8',$out_encoding = 'UCS-2') {
$return = '';
if (function_exists('mb_get_info')) {
for($x = 0; $x < mb_strlen ( $string, $in_encoding ); $x ++) {
$str = mb_substr ( $string, $x, 1, $in_encoding );
if (strlen ( $str ) > 1) { // 多字節(jié)字符
$return .= '%u' . strtoupper ( bin2hex ( mb_convert_encoding ( $str, $out_encoding, $in_encoding ) ) );
} else {
$return .= '%' . strtoupper ( bin2hex ( $str ) );
}
}
}
return $return;
}


對應(yīng)的解碼php unescape代碼是:

復(fù)制代碼 代碼如下:
function unescape($str)
{
$ret = '';
$len = strlen($str);
for ($i = 0; $i < $len; $i ++)
{
if ($str[$i] == '%' && $str[$i + 1] == 'u')
{
$val = hexdec(substr($str, $i + 2, 4));
if ($val < 0x7f)
$ret .= chr($val);
else
if ($val < 0x800)
$ret .= chr(0xc0 | ($val >> 6)) .
chr(0x80 | ($val & 0x3f));
else
$ret .= chr(0xe0 | ($val >> 12)) .
chr(0x80 | (($val >> 6) & 0x3f)) .
chr(0x80 | ($val & 0x3f));
$i += 5;
} else
if ($str[$i] == '%')
{
$ret .= urldecode(substr($str, $i, 3));
$i += 2;
} else
$ret .= $str[$i];
}
return $ret;
}

分享:解析php session_set_save_handler 函數(shù)的用法(mysql)
本篇文章是對php中session_set_save_handler 函數(shù)的用法(mysql)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下 復(fù)制代碼 代碼如下: ?php /*============================文件說明======================================== @filename: session.class.php @description: 數(shù)據(jù)庫

來源:模板無憂//所屬分類:PHP教程/更新時間:2013-07-01
相關(guān)PHP教程