您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

关于PHP递归数组代码分析_PHP教程

2024/4/17 7:37:11发布13次查看
我们大家都知道php是一种html内嵌式的语言,php与微软的asp颇有几分相似,都是一种在服务器端执行的嵌入html文档的脚本语言,语言的风格有类似于c语言,现在被很多的网站编程人员广泛的运用。文章这里详细的介绍一下php递归数组。php程序需要将接收到的数据同时写到“线上运行的正式数据库”和“进行开发调试的测试数据库”。
而测试数据库可能经常会面临对表结构、字段、配置信息做调整等问题,很不稳定,发生错误的概率很高,如果用a.php程序同时写“正式数据库”和 “测试数据库”,势必影响到线上运行的正式服务。于是,我想到用php curl扩展库将生成的$data数组post传递一份给php程序,然后php程序继续往下执行写“正式数据库”的代码。php程序将$data数组传递给php程序就完事了,至于php如何处理,就不关php的事了,php程序即使写“测试数据库”失败,也不会对 php程序造成影响。php递归数组源代码:
php $data[username]=张宴;  $data[password]=不知道;  $data[ip]=192.168.0.18;  //register_shutdown_function(post_data, $data);  //function post_data($data)  //{  $curl = new curl_class();  $post = @$curl->post(http://127.0.0.1/b.php, $data);//这里是b.php的访问地址,请自行修改  //}  //curl类  class curl_class  {  function curl_class()  {  return true;  }  function execute($method, $url, $fields = '', $useragent = '', $httpheaders = '', $username = '', $password = '')  {  $ch = curl_class::create();  if (false === $ch)  {  return false;  }  if (is_string($url) && strlen($url))  {  $ret = curl_setopt($ch, curlopt_url, $url);  }  else  {  return false;  }  //是否显示头部信息  curl_setopt($ch, curlopt_header, false);  //  curl_setopt($ch, curlopt_returntransfer, true);  if ($username != '')  {  curl_setopt($ch, curlopt_userpwd, $username . ':' . $password);  }  $method = strtolower($method);  if ('post' == $method)  {  curl_setopt($ch, curlopt_post, true);  if (is_array($fields))  {  $sets = array();  foreach ($fields as $key => $val)  {  $sets[] = $key . '=' . urlencode($val);  }  $fields = implode('&',$sets);  }  curl_setopt($ch, curlopt_postfields, $fields);  }  else if ('put' == $method)  {  curl_setopt($ch, curlopt_put, true);  }  //curl_setopt($ch, curlopt_progress, true);  //curl_setopt($ch, curlopt_verbose, true);  //curl_setopt($ch, curlopt_mute, false);  curl_setopt($ch, curlopt_timeout, 3);//设置curl超时秒数,例如将信息post出去3秒钟后自动结束运行。  if (strlen($useragent))  {  curl_setopt($ch, curlopt_useragent, $useragent);  }  if (is_array($httpheaders))  {  curl_setopt($ch, curlopt_httpheader, $httpheaders);  }  $ret = curl_exec($ch);  if (curl_errno($ch))  {  curl_close($ch);  return array(curl_error($ch), curl_errno($ch));  }  else  {  curl_close($ch);  if (!is_string($ret) || !strlen($ret))  {  return false;  }  return $ret;  }  }  function post($url, $fields, $useragent = '', $httpheaders = '', $username = '', $password = '')  {  $ret = curl_class::execute('post', $url, $fields, $useragent, $httpheaders, $username, $password);  if (false === $ret)  {  return false;  }  if (is_array($ret))  {  return false;  }  return $ret;  }  function get($url, $useragent = '', $httpheaders = '', $username = '', $password = '')  {  $ret = curl_class::execute('get', $url, '', $useragent, $httpheaders, $username, $password);  if (false === $ret)  {  return false;  }  if (is_array($ret))  {  return false;  }  return $ret;  }  function create()  {  $ch = null;  if (!function_exists('curl_init'))  {  return false;  }  $ch = curl_init();  if (!is_resource($ch))  {  return false;  }  return $ch;  }  }  ?> 
php递归数组代码:
php    ignore_user_abort();//连线中断后(例如关闭浏览器)仍然继续执行以下的脚本直到处理完毕。  set_time_limit(0);  $get_data = file_get_contents(php://input);  $explodeexplodedata = explode(&, $get_data);  foreach ($explodedata as $key => $value)//还原数组  {  list($realkey, $realvalue) = explode(=, $value);  $data[urldecode($realkey)] = urldecode($realvalue);  }  //现在$data数组已经和a.php中的一样了,接下来,就可以根据自己的需要对$data数组进行操作了。  //......  ?> 
http://www.bkjia.com/phpjc/446465.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/446465.htmltecharticle我们大家都知道php是一种html内嵌式的语言,php与微软的asp颇有几分相似,都是一种在服务器端执行的嵌入html文档的脚本语言,语言的风格...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product