随笔分类 -  PHP基础

MySQL 字段值为NULL,PHP用json转换,传给js,显示null
摘要:这个问题出在php的json_encode环节,这个函数返回的json数据中会把空值写作null。想通过在js端这样把null转为空字符串是不可以的:JSON.parse(JSON.stringify(text));因为JSON的键值对必须双方都不为空。那么简单的办法就是在最终使用字符串的地方整个用str.replace(/null/g, '')替换一下。 阅读全文
posted @ 2013-09-24 17:36 any91 阅读(785) 评论(0) 推荐(0)
PHP比较IP大小
摘要:function cmpLoginIP($a, $b){ return bindec(decbin(ip2long($a['loginIp']))) > bindec(decbin(ip2long($b['loginIp'])));}function cmpLoginIPDesc($a, $b){ return bindec(decbin(ip2long($b['loginIp']))) > bindec(decbin(ip2long($a['loginIp'])));} 阅读全文
posted @ 2013-09-17 10:29 any91 阅读(700) 评论(0) 推荐(0)
Apache中Cookie长度的设置 414 request-uri too large apache
摘要:起因:今天在调试Ucenter的同步登陆和同步登出的过程中,浏览器突然出现以下错误提示:Your browser sent a request that this server could not understand.Size of a request header field exceeds server limit.开始是以为P3P协议设置cookie的问题,查阅了P3P的文档,没有相关的条目。经过不懈的搜索,终于发现原来是Apache中资源使用限制的设置问题。技术背景:Apache中“资源使用限制”就是要限制用户对网站特定资源(如目录、服务器硬件等)的访问。相关指令包括:LimitRe 阅读全文
posted @ 2013-09-05 17:17 any91 阅读(1588) 评论(0) 推荐(0)
URL中文参数,JSON转换,PHP赋值JS
摘要:var jsonProps = { "dispMode":dispMode, "autoRun":autoRun, "clientPath":encodeURI(clientPath), "remark":encodeURI(remark) }; $.ajax({ url:"./process/writeTask.php", data:"proType=setTask&taskId=" + taskId + "&props=" + JSON 阅读全文
posted @ 2013-09-05 10:19 any91 阅读(510) 评论(0) 推荐(0)
PHP通过JSON给JS赋值;JS通过JSON给PHP传值
摘要:$fileNames = array(); // 是数组,不是字符串$filesJSON = json_encode($fileNames);// 转成json格式var oldFiles = new Array();//oldFiles = '';// 这样oldFiles成字符串了,而不是json数据oldFiles = JSON.parse('');// JSON格式即为数组格式------------------------------------------------------------------------------------------ 阅读全文
posted @ 2013-08-29 16:42 any91 阅读(1173) 评论(0) 推荐(0)
PHP限制上传文件大小
摘要:在php.ini中修改如下变量,如要限制为100Mupload_max_filesize = 100Mpost_max_size = 100M重启Apache 阅读全文
posted @ 2013-08-29 14:22 any91 阅读(187) 评论(0) 推荐(0)
PHP 类中使用全局变量和全局常量
摘要:_var = $global_var; // 全局常量不可以通过global传入 //global global_const; } }$test = new Test();echo $test->_var;echo $test->_const;?> 阅读全文
posted @ 2013-08-29 11:20 any91 阅读(8346) 评论(0) 推荐(0)
PHP 输出XML字符串
摘要: 阅读全文
posted @ 2013-08-27 14:43 any91 阅读(258) 评论(0) 推荐(0)
foreach数组并直接改变数组内容
摘要: 阅读全文
posted @ 2013-08-13 09:27 any91 阅读(509) 评论(0) 推荐(0)
基于jquery,php实现AJAX长轮询(LongPoll),类似推送机制
摘要:HTTP是无状态、单向的协议,用户只能够通过客服端向服务器发送请求并由服务器处理发回一个响应。若要实现聊天室、WEBQQ、在线客服、邮箱等这些即时通讯的应用,就要用到“ 服务器推送技术(Comet)”。传统的AJAX轮询方式,客服端以用户定义的时间间隔去服务器上查询最新的数据。种这种拉取数据的方式需要很短的时间间隔才能保证数据的精确度,但太短的时间间隔客服端会对服务器在短时间内发送出多个请求。反转AJAX,就是所谓的长轮询或者COMET。服务器与客服端需要保持一条长时间的请求,它使得服务器在有数据时可以返回消息给客户端。 html:[html] view plaincopyjavascript 阅读全文
posted @ 2013-08-12 14:11 any91 阅读(488) 评论(1) 推荐(0)
如何在sprintf函数中输出百分号(%)等特殊符号
摘要:php中的sprinf可以格式化字符串的数据类型。今天遇到了想在其中输出%,可难倒我了。$query = sprintf("select * from books where %s like '% %s %'",$searchtype,$searchterm);//我以为输出是这样的:select * from books wheretitle like '%java %' ,但实际上输出会是select * from books wheretitle like '%将其换成这样就可以了:$query = sprintf(" 阅读全文
posted @ 2013-08-03 11:15 any91 阅读(9577) 评论(0) 推荐(0)