91亚洲精华国内精华精华液_国产高清在线精品一区不卡_精品特级一级毛片免费观看_欧美日韩中文制服有码_亚洲精品无码你懂的网站369

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

  • 淺析使用PHP邏輯運算符
  • 關(guān)于Windows PHP配置應(yīng)用程序服務(wù)器步驟
  • 關(guān)于Windows下安裝PHP5配置詳細(xì)介紹
  • 詳細(xì)介紹對象PHP串行化
  • 詳談PHP WEB服務(wù)器相關(guān)知識

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

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

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

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

  1. php    
  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ù)組進行操作了。  
  12. //......  
  13. ?>

 

穩(wěn)定

產(chǎn)品高可用性高并發(fā)

貼心

項目群及時溝通

專業(yè)

產(chǎn)品經(jīng)理1v1支持

快速

MVP模式小步快跑

承諾

我們選擇聲譽

堅持

10年專注高端品質(zhì)開發(fā)
  • 返回頂部