PHP function ob_star () tips _ PHP Tutorial

Source: Internet
Author: User
Tips for using PHP function ob_star. Today we will introduce some functions that directly generate output in PHP programming, such as passthru (), readfile (), var_dump. but sometimes we want to introduce this to you today.In PHP programming, we often encounter some functions that directly generate output, such as passthru (), readfile (), and var_dump. however, sometimes we want to import the output of these functions to a file, or process the output of these functions as strings.

Now we need to use the PHP function ob_star.

There are several main functions for processing the output buffer:

The PHP function ob_star () starts to output the buffer. at this time, PHP stops the output and the output will be transferred to an internal buffer.

The ob_get_contents () function returns the content of the internal buffer. this is equivalent to converting these outputs into strings.

Ob_get _ length () returns the length of the internal buffer.

Ob_end_flush () ends the output buffer and outputs the content in the buffer. after that, the output is normal.

Ob_end_clean () ends the output buffer and discards the content in the buffer.

For example, the var_dump () function outputs the structure and content of a variable, which is useful during debugging.
However, if the variable content contains special HTML characters such as <,>, the output will be invisible to the webpage. what should I do?
The PHP function ob_star () can easily solve this problem.

 
 
  1. ob_start();
  2. var_dump($var);
  3. $out = ob_get_contents();
  4. ob_end_clean();

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

 
 
  1. echo '< pre>' . htmlspec
    ialchars($out) . '< /pre>' ;

Or wait for the future, or send this string to the Template and then output it.

The above is the functional advantages of PHP function ob_star.


Pipeline in PHP programming, we often encounter some functions that directly generate output, such as passthru (), readfile (), var_dump (). 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.