PHP4 new function highlights

xiaoxiao2021-03-06  108

First, the output information control function

These functions allow you to control your script output. You can use many different situations, especially when your script has already output information, you need to send file header. The output control function does not use header () or setcookie. ) The sending file header information has an impact, only the data blocks similar to ECHO () and PHP code.

Example 1. Control output

Ob_start ();

Echo "Hellon";

SetCookie ("Cookiename", "cookiedata");

OB_END_FLUSH ();

?>

In the above example, the output content using ECHO () will be saved in the output buffer until OB_END_FLUSH () is called. This means that the content calling setCookie () is successfully stored in the cookie Not causing errors. (Under normal circumstances, you can't send file header information to user browsers after having data has been sent.)

Related function header () and setcookie ().

Han number list

Flush - Refresh Output Buffer

Save the content in the output buffer will be sent to the browser

OB_Start - Open Output Buffer

Such all output information is not sent directly to the browser, but is saved inside the output buffer.

OB_GET_CONTENTS - Returns the contents of the output buffer

If you want to process the contents of the output, you can call this function to keep a backup

OB_GET_LENGTH - Returns the content length of the output buffer

OB_END_FLUSH - End (Send) Output Buffer content, turn off output buffer

OB_END_CLEAN - Delete (Abandon) Output Buffer, Turn off Output Buffer

If your program finds a problem with the output content, you can give up all output content, prevent some secret information from leaking

OB_IMPLICIT_FLUSH - Open or close Direct Refresh

After opening, each script output is sent directly to the browser, no longer need to call Flush ()

Second, get the current directory

This is a new directory function of PHP4!

String getCwd (void)

Returns a string for the current script path!

Third, solve the script timeout

There is a function of setting a script execution time in the configuration / information of the PHP, and the specific situation is as follows:

SET_TIME_LIMIT

Configure this page to execute time.

Syntax: void set_time_limit (int seconds);

Return value: no

Function type: PHP system function

Content description

This function is used to configure this page to execute time. The default is 30 seconds, in the Max_execution_time variable configuration in php.ini, if it is configured to be 0, no longer time. The calculation is started when the function is executed. For example, if the default is 30 seconds, 25 seconds have been executed before the function is executed, and this function is changed to 20 seconds, then the maximum execution time is 45 seconds.

Use example:

My article search function is often made of timeout errors due to the increase in the number of articles. I change the script to 200 seconds.

Four, array traversal · Foreach In php4, add a loop statement foreach, it is very like Perl and other languages, you can give it an array to remove the array value. It has the following two syntax, the second syntax is more important, but can be used as an extension of the first syntax. Foreach (array_expression as $ value) Statement Foreach (Array_Expression AS $ Key => $ VALUE) STATEMENT The first form of loop, which will assign the value of the current element to $ VALUE in each loop, and move the array backward The internal pointer, so you will see the next element when the next cycle. The second form of loops is the same, and the difference is that it assigns the index value of the current element to the variable $ KEY at each loop. Note: When Foreach first starts executing, it will reset the internal pointer of the array to the first element of the array. It means that you don't have to call Reset () before using foreach. Note: Foreach's function is replicated, not the array it itself, so it does not change the function of the parameters below the parameter: ";} foreach ($ arr as $ value) {echo "value: $ value
"}?>

The features of the examples are also the same:

"} foreach ($ arr as $ Key => $ value) {echo "key: $ key; value: $ value
";}?>

The following example will explain the usage of Foreach:

1, "two" => 2, "three" => 3, "seventeen" => 17); Foreach ($ A as $ K => $ V) {Print "$ A [$ K] => $ V.";

转载请注明原文地址:https://www.9cbs.com/read-101488.html

New Post(0)