有什麼辦法可以在PHP中享受decodeValue()
函數嗎?我將這些encodedValue值發佈到PHP文件中,我需要在PHP中以數組的形式使用它們。ExtJS:DecodeValue in PHP
我該如何結束一個PHP數組或從Ext編碼狀態的東西?或者,有沒有其他方法可以使編碼的值能夠在PHP中輕鬆讀取?以下是功能代碼:
decodeValue : function(cookie){
var re = /^(a|n|d|b|s|o)\:(.*)$/;
var matches = re.exec(unescape(cookie));
if(!matches || !matches[1]) return; // non state cookie
var type = matches[1];
var v = matches[2];
switch(type){
case "n":
return parseFloat(v);
case "d":
return new Date(Date.parse(v));
case "b":
return (v == "1");
case "a":
var all = [];
var values = v.split("^");
for(var i = 0, len = values.length; i < len; i++){
all.push(this.decodeValue(values[i]));
}
return all;
case "o":
var all = {};
var values = v.split("^");
for(var i = 0, len = values.length; i < len; i++){
var kv = values[i].split("=");
all[kv[0]] = this.decodeValue(kv[1]);
}
return all;
default:
return v;
}
}
謝謝。