日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
關(guān)于PHP遞歸數(shù)組代碼分析

我們大家都知道PHP是一種HTML內(nèi)嵌式的語言,PHP與微軟的ASP頗有幾分相似,都是一種在服務(wù)器端執(zhí)行的嵌入HTML文檔的腳本語言,語言的風(fēng)格有類似于C語言,現(xiàn)在被很多的網(wǎng)站編程人員廣泛的運(yùn)用。文章這里詳細(xì)的介紹一下PHP遞歸數(shù)組。PHP程序需要將接收到的數(shù)據(jù)同時(shí)寫到“線上運(yùn)行的正式數(shù)據(jù)庫”和“進(jìn)行開發(fā)調(diào)試的測試數(shù)據(jù)庫”。

#T#而測試數(shù)據(jù)庫可能經(jīng)常會(huì)面臨對表結(jié)構(gòu)、字段、配置信息做調(diào)整等問題,很不穩(wěn)定,發(fā)生錯(cuò)誤的概率很高,如果用a.php程序同時(shí)寫“正式數(shù)據(jù)庫”和 “測試數(shù)據(jù)庫”,勢必影響到線上運(yùn)行的正式服務(wù)。于是,我想到用PHP curl擴(kuò)展庫將生成的$data數(shù)組post傳遞一份給php程序,然后php程序繼續(xù)往下執(zhí)行寫“正式數(shù)據(jù)庫”的代碼。php程序?qū)?data數(shù)組傳遞給php程序就完事了,至于php如何處理,就不關(guān)php的事了,php程序即使寫“測試數(shù)據(jù)庫”失敗,也不會(huì)對 php程序造成影響。

PHP遞歸數(shù)組源代碼:

 
 
  1. $data["username"]="張宴";
  2. $data["password"]="不知道";
  3. $data["ip"]="192.168.0.18";
  4. //reGISter_shutdown_function("post_data", $data);
  5. //function post_data($data)
  6. //{
  7. $curl = new Curl_Class();
  8. $post = @$curl->post("http://127.0.0.1/b.php", $data);//這里是b.php的訪問地址,請自行修改
  9. //}
  10. //curl類
  11. class Curl_Class
  12. {
  13. function Curl_Class()
  14. {
  15. return true;
  16. }
  17. function execute($method, $url, $fields = '', $userAgent = '', $httpHeaders = '', $username = '', $password = '')
  18. {
  19. $ch = Curl_Class::create();
  20. if (false === $ch)
  21. {
  22. return false;
  23. }
  24. if (is_string($url) && strlen($url))
  25. {
  26. $ret = curl_setopt($ch, CURLOPT_URL, $url);
  27. }
  28. else
  29. {
  30. return false;
  31. }
  32. //是否顯示頭部信息
  33. curl_setopt($ch, CURLOPT_HEADER, false);
  34. //
  35. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  36. if ($username != '')
  37. {
  38. curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
  39. }
  40. $method = strtolower($method);
  41. if ('post' == $method)
  42. {
  43. curl_setopt($ch, CURLOPT_POST, true);
  44. if (is_array($fields))
  45. {
  46. $sets = array();
  47. foreach ($fields AS $key => $val)
  48. {
  49. $sets[] = $key . '=' . urlencode($val);
  50. }
  51. $fields = implode('&',$sets);
  52. }
  53. curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
  54. }
  55. else if ('put' == $method)
  56. {
  57. curl_setopt($ch, CURLOPT_PUT, true);
  58. }
  59. //curl_setopt($ch, CURLOPT_PROGRESS, true);
  60. //curl_setopt($ch, CURLOPT_VERBOSE, true);
  61. //curl_setopt($ch, CURLOPT_MUTE, false);
  62. curl_setopt($ch, CURLOPT_TIMEOUT, 3);//設(shè)置curl超時(shí)秒數(shù),例如將信息POST出去3秒鐘后自動(dòng)結(jié)束運(yùn)行。
  63. if (strlen($userAgent))
  64. {
  65. curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
  66. }
  67. if (is_array($httpHeaders))
  68. {
  69. curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
  70. }
  71. $ret = curl_exec($ch);
  72. if (curl_errno($ch))
  73. {
  74. curl_close($ch);
  75. return array(curl_error($ch), curl_errno($ch));
  76. }
  77. else
  78. {
  79. curl_close($ch);
  80. if (!is_string($ret) || !strlen($ret))
  81. {
  82. return false;
  83. }
  84. return $ret;
  85. }
  86. }
  87. function post($url, $fields, $userAgent = '', $httpHeaders = '', $username = '', $password = '')
  88. {
  89. $ret = Curl_Class::execute('POST', $url, $fields, $userAgent, $httpHeaders, $username, $password);
  90. if (false === $ret)
  91. {
  92. return false;
  93. }
  94. if (is_array($ret))
  95. {
  96. return false;
  97. }
  98. return $ret;
  99. }
  100. function get($url, $userAgent = '', $httpHeaders = '', $username = '', $password = '')
  101. {
  102. $ret = Curl_Class::execute('GET', $url, '', $userAgent, $httpHeaders, $username, $password);
  103. if (false === $ret)
  104. {
  105. return false;
  106. }
  107. if (is_array($ret))
  108. {
  109. return false;
  110. }
  111. return $ret;
  112. }
  113. function create()
  114. {
  115. $ch = null;
  116. if (!function_exists('curl_init'))
  117. {
  118. return false;
  119. }
  120. $ch = curl_init();
  121. if (!is_resource($ch))
  122. {
  123. return false;
  124. }
  125. return $ch;
  126. }
  127. }
  128. ?>

PHP遞歸數(shù)組代碼:

 
 
  1.   
  2. ignore_user_abort();//連線中斷后(例如關(guān)閉瀏覽器)仍然繼續(xù)執(zhí)行以下的腳本直到處理完畢。
  3. set_time_limit(0);
  4. $get_data = file_get_contents("php://input");
  5. $explodeexplodedata = explode("&", $get_data);
  6. foreach ($explodedata as $key => $value)//還原數(shù)組
  7. {
  8. list($realkey, $realvalue) = explode("=", $value);
  9. $data[urldecode($realkey)] = urldecode($realvalue);
  10. }
  11. //現(xiàn)在$data數(shù)組已經(jīng)和a.php中的一樣了,接下來,就可以根據(jù)自己的需要對$data數(shù)組進(jìn)行操作了。
  12. //......
  13. ?>

本文題目:關(guān)于PHP遞歸數(shù)組代碼分析
轉(zhuǎn)載注明:http://m.5511xx.com/article/cdsspoc.html