Measure the test taker's knowledge about the efficiency of the PHPob_start () function.

Source: Internet
Author: User
The main functional points of PHPob_start () functions are explained in detail. PHP functions are widely used. we can continue to learn the benefits of these functions. Next we will analyze the features of the PHPob_start () function. For example, you can obtain the settings of the server and client, but this information details the functional points of the PHP ob_start () function.
PHP functions are widely used. we can learn the benefits of these functions in practice. Next we will analyze the functional features of the PHP ob_start () function.

For example, you can obtain the configuration information of the server and the client, but this information may vary depending on the client. what if you want to save the output of the phpinfo () function? There is no way to control the buffer, but with the control of the buffer, we can easily solve the problem:

1. <? Php
2. ob_start (); // open the buffer
3. phpinfo (); // use the phpinfo function
4. $ info = ob_get_contents (); // Obtain the buffer content and assign it to $ info
5. export file1_fopen('info.txt ', 'w'); // open the info.txt file.
6. fwrite ($ file, $ info); // write the information to info.txt
7. fclose ($ file); // Close the info.txt file
8.?>

With the above method, you can save the phpinfo information of different users. I am afraid there is no way to do this before! In fact, the above is how to convert some "procedures" into "functions!

Someone may ask, "is it like this? Is there any other purpose ?" Of course, for example, the PHP syntax highlighted by the Author Forum is related to this (the default PHP syntax highlighted by the display function will be directly output and the results cannot be saved, I am afraid it will be a waste of CPU if it is displayed in every call. in my forum, I will keep the result of the function highlighted by the syntax in the method of controlling the buffer ).

You may now have some knowledge about the functions of PHP ob_start () functions. the above example seems simple, but you have mastered the key points of using ob_start.

<1>. use the PHP ob_start () function to open the browser cache. This ensures that the cache content will not be output before you call flush (), ob_end_flush () (or after the program is executed.

<2>. now you should know your advantages: you can use headers, setcookies, and sessions after any output content, which is a great feature of PHP ob_start () functions; you can also use the ob_start parameter to automatically run commands after the cache is written, such as ob_start ("ob_gzhandler"). The most common practice is to use ob_get_contents () get the content in the cache and then process it ......

<3>. after processing is completed, we can use various methods for output, flush (), ob_end_flush (), and automatic output after the program is executed. Of course, if you use ob_get_contents (), you can control the output mode by yourself.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.