php function Ob_star () the specific use of tips to share _php tutorials

Source: Internet
Author: User
We are going to introduce to you todayIn PHP programming, we often encounter some functions that produce output directly, such as PassThru (), ReadFile (), Var_dump (), and so on. But sometimes we want to import the output of these functions into a file, or go through processing and re-output, Or the output of these functions is treated as a string.

At this point we are going to use PHP function Ob_star ().

There are several main functions that handle output buffering:

php function Ob_star () starts the output buffer, when PHP stops the output, after which the output is transferred to an internal buffer.

Ob_get_contents () This function returns the contents of the internal buffer. This is tantamount to turning these outputs into strings.

Ob_get_ Length () returns the size of the internal buffer.

Ob_end_flush () ends the output buffer and outputs the contents of the buffer. After that, the output is normal output.

Ob_end_clean () ends the output buffer and discards the contents of the buffer.

For example, the Var_dump () function outputs the structure and contents of a variable, which is useful when debugging.
But if the contents of the variable have <, > and other special characters of HTML, the output to the Web page is not visible. What do we do?
It is easy to solve this problem with PHP function Ob_star ().

 
  
  
  1. Ob_start ();
  2. Var_dump ($var);
  3. $ out ob_get_contents();

At this time the output of var_dump () already exists $out. You can output it now:

 
  
  
  1. Echo ' < pre>'. Htmlspec
    Ialchars ($out). '< /pre>

Or wait until the future, or send the string to the template and then output.

This is the functional advantage Comparison of PHP function Ob_star ().


http://www.bkjia.com/PHPjc/446220.html www.bkjia.com true http://www.bkjia.com/PHPjc/446220.html techarticle we are going to introduce ourselves to you today. In PHP programming, we often encounter some functions that produce output directly, such as PassThru (), ReadFile (), Var_dump (), and so on. But sometimes we want to put these ...

  • 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.