php 常见问题及解决方法
(1)请求要素是json字符串,后台如何获取
//this is a common php library by huangwei ,//date:2014-07-03//see http://blog.sina.com.cn/s/blog_4657e98e0100dyxp.html//see http://www.cnblogs.com/fullhouse/archive/2012/04/24/2468870.htmlif(array_key_exists(HTTP_RAW_POST_DATA,)){//判断是否有key-HTTP_RAW_POST_DATA=[HTTP_RAW_POST_DATA];//always_populate_raw_post_data = On}if (empty()) { =;}if (empty()) { =file_get_contents(php://input); }if(empty()) { =;}if(empty()) { =;}(2)如何把接收到的json字符串转化为对象
= json_decode();(3)如何把json对象转化为数组
//convert object to arrayfunction object_to_array(){ if(is_array()){ return ; } = is_object()? get_object_vars() :; foreach ( as => ){ =(is_array()) || is_object() ? object_to_array() :; [] = ; } return ; }(4)获取php服务器操作系统类型
/*** @return string : windows or linux*/function serverOS(){ =strtolower(php_uname(s)); =strpos(,linux); if( === false) { return windows; } else { return linux; }}应用:
;if(serverOS()==linux){ =-9;}else{ =32;}[webroot]=substr(dirname(__FILE__), 0, );///var/www/html/exchange(5)字符串a是否包含字符串b
function strexists(, ){ return !(strpos(, ) === FALSE);}(6)递归创建文件夹
function mkdirs(){ return is_dir() or (mkdirs(dirname()) and mkdir(, 0777));}

发表评论 取消回复