We all know that PHP is an embedded HTML language. PHP is similar to Microsoft's ASP, and it is a script language that is executed on the server to embed HTML documents, the language style is similar to the C language and is widely used by many website programmers. This article introduces PHP recursive arrays in detail. The PHP program needs to write the received data to both the "official database running online" and the "test database for development and debugging ".
However, the test database may often face problems such as adjusting the table structure, fields, and configuration information. It is very unstable and has a high probability of errors. If a is used. php programs write "official database" and "Test Database" at the same time, which will inevitably affect the official services running online. So I want to use the PHP curl extension library to pass the generated $ data array post to the php program, and then the php program continues to execute the code to write the "official database. The php program will pass the $ data array to the php program. As for how php is handled, it will not be related to php. Even if the php program fails to write "Test Database, it will not affect the php program.
PHP recursive array source code:
- <?Php
- $ Data ["username"] = "banquet ";
- $ Data ["password"] = "unknown ";
- $ Data ["ip"] = "192.168.0.18 ";
- // ReGISter_shutdown_function ("post_data", $ data );
- // Function post_data ($ data)
- //{
- $Curl=NewCurl_Class ();
- $Post= @ $ Curl->Post ("http: // 127.0.0.1/B. php", $ data); // The access address of B. php is here. Modify it by yourself.
- //}
- // Curl class
- 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;
- }
- // Whether the header information is displayed
- 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); // sets the curl timeout time in seconds. For example, the system automatically stops running after three seconds of posting information.
- 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 recursive array code:
- <?Php
- Ignore_user_abort (); // after the connection is interrupted (for example, the browser is closed), the following script continues to be executed until the processing is completed.
- Set_time_limit (0 );
- $Get_data=File_get_contents("Php: // input ");
- $ExplodeExplodedata= Explode ("&", $ get_data );
- Foreach ($ explodedata as $Key=>$ Value) // restore the Array
- {
- List ($ realkey, $ realvalue) = explode ("=", $ value );
- $ Data [urldecode ($ realkey)] = urldecode ($ realvalue );
- }
- // Now the $ data array is the same as that in a. php. Next, you can operate the $ data array as needed.
- //......
- ?>