后端开发|php教程
quot,substr,var,Str,substring
后端开发-php教程
资料链接:/blog/105669
本源码不存在运营问题,vscode 转化为大写,ubuntu动态时间,访问tomcat上层,sqlite字符串类型,洗脸盆地漏爬虫子,php 正则多行,朴敏京seo,最新asp网站源码下载,html网页做一个打字小游戏,伊人集模板下载lzw
1、PHP中的 json_encode 函数只限编码UTF-8的数据,当转换GBK或者GB2312等编码的数据时,会将汉字转为NULL。
系统优化 源码,vscode配置lua开发,ssh 连接ubuntu,tomcat突然不能用,爬虫女装,php快速查找,理解SEO的发展状况,代理在线下单网站源码,dede高仿模板堂魔客吧lzw
2、JavaScript 中json 的使用:
微信热文内容采集源码,ubuntu 图标到桌面,爬虫和cc攻击,php背景图片下方有留白,小星seo教程lzw
① 将对象转为json字符串:
JSON.stringify(obj)
② 将json转为对象:
dataObj = eval(‘{“name”:”Jack”}’);
③ 将PHP生成的json转为对象:
dataObj = eval(‘(‘Jack’))?>)’);
3、JavaScript 中,GBK和UTF-8的转换:
function GB2312UTF8(){this.Dig2Dec=function(s){var retV = 0;if(s.length == 4){ for(var i = 0; i < 4; i ++){retV += eval(s.charAt(i)) * Math.pow(2, 3 - i); } return retV;}return -1;} this.Hex2Utf8=function(s){var retS = "";var tempS = "";var ss = "";if(s.length == 16){ tempS = "1110" + s.substring(0, 4); tempS += "10" + s.substring(4, 10); tempS += "10" + s.substring(10,16); var sss = "0123456789ABCDEF"; for(var i = 0; i < 3; i ++){ retS += "%"; ss = tempS.substring(i * 8, (eval(i)+1)*8); retS += sss.charAt(this.Dig2Dec(ss.substring(0,4))); retS += sss.charAt(this.Dig2Dec(ss.substring(4,8))); } return retS;}return "";} this.Dec2Dig=function(n1){var s = "";var n2 = 0;for(var i = 0; i = n2){ s += 1; n1 = n1 - n2; } else s += ;}return s;}this.Str2Hex=function(s){var c = "";var n;var ss = "0123456789ABCDEF";var digS = "";for(var i = 0; i < s.length; i ++){ c = s.charAt(i); n = ss.indexOf(c); digS += this.Dec2Dig(eval(n));}return digS;}this.Gb2312ToUtf8=function(s1){ var s = escape(s1); var sa = s.split("%"); var retV =""; if(sa[0] != ""){retV = sa[0]; } for(var i = 1; i < sa.length; i ++){if(sa[i].substring(0,1) == "u"){retV += this.Hex2Utf8(this.Str2Hex(sa[i].substring(1,5))); if(sa[i].length){ retV += sa[i].substring(5); }}else{retV += unescape("%" + sa[i]); if(sa[i].length){ retV += sa[i].substring(5); } } } return retV;}this.Utf8ToGb2312=function(str1){var substr = "";var a = "";var b = "";var c = "";var i = -1;i = str1.indexOf("%");if(i==-1){ return str1;}while(i!= -1){ if(i<3){substr = substr + str1.substr(0,i-1);str1 = str1.substr(i+1,str1.length-i);a = str1.substr(0,2);str1 = str1.substr(2,str1.length - 2);if(parseInt("0x" + a) & 0x80 == 0){ substr = substr + String.fromCharCode(parseInt("0x" + a));}else if(parseInt("0x" + a) & 0xE0 == 0xC0){ //two byteb = str1.substr(1,2);str1 = str1.substr(3,str1.length - 3);var widechar = (parseInt("0x" + a) & 0x1F) << 6;widechar = widechar | (parseInt("0x" + b) & 0x3F);substr = substr + String.fromCharCode(widechar);}else{b = str1.substr(1,2);str1 = str1.substr(3,str1.length - 3);c = str1.substr(1,2);str1 = str1.substr(3,str1.length - 3);var widechar = (parseInt("0x" + a) & 0x0F) << 12;widechar = widechar | ((parseInt("0x" + b) & 0x3F) << 6);widechar = widechar | (parseInt("0x" + c) & 0x3F);substr = substr + String.fromCharCode(widechar);}}else {substr = substr + str1.substring(0,i);str1= str1.substring(i);}i = str1.indexOf("%");}return substr+str1;}}
以上就介绍了JS中utf8和GBK的字符编码转换,包括了方面的内容,希望对PHP教学有兴趣的朋友有所帮助。