search
HomeBackend DevelopmentPHP TutorialTeach you how to use the ob function to output static html files

How to use the ob function to output static html files

1. Introduction to the ob function

1.1. ob_start - open the output control buffer

bool ob_start ([ callback $output_callback [, int $chunk_size [, bool $erase ]]] )
This function will open the output buffer. When output buffering is activated, the script will not output content (except http headers), instead the content to be output is stored in an internal buffer.
Reference for details:
#1.2, ob_get_contents - Return the contents of the output buffer

##string ob_get_contents ( void )Just get the output buffer area, but does not clear it. Reference for details:


##1.3, ob_end_flush — flush out (send out) the contents of the output buffer and close the buffer

##bool ob_end_flush ( void )This function will send the contents of the top-level buffer (if there is content inside) and close the buffer. If you want to further process the contents of the buffer, you must call ob_get_contents() before ob_end_flush(), because the buffer contents are discarded after calling ob_end_flush(). Reference for details:


##1.4, ob_flush - flush out (send) the contents of the output buffer

##void ob_flush ( void )This function will send out the contents of the buffer (if there is content inside if). If you want to further process the contents of the buffer, you must call ob_get_contents() before ob_flush(), because the buffer contents will be discarded after calling ob_flush(). This function will not destroy the output buffer, but functions like ob_end_flush() will destroy the buffer. Reference for details:



##1.5, ob_get_clean - get the contents of the current buffer and delete the current output buffer

#string ob_get_clean ( void )Get the contents of the current buffer and delete the current output buffer. ob_get_clean() essentially executes ob_get_contents() and ob_end_clean() together. Reference for details:


##1.6, ob_get_flush - Flush (send out) the buffer content, return the content in the form of a string, and close the output buffer

#string ob_get_flush ( void )ob_get_flush() flushes (sends out) the contents of the buffer, returns the contents as a string, and closes the output buffer.
Note: This function is similar to ob_end_flush(), except that this function also returns the buffer content in string form.
Reference for details:
##2. How to use the ob() function to create a static page of html

2.1. Simple output html file

#ob_start(); //Open buffering District$info = 'hello world! ! ';
$file=fopen('index.html','w'); //Open the file index.html
fwrite($file,$info); //Write information to index.html
fclose($file); //Close the file index.html
?>
Output hello to index.html


Find index.html, and output the setting normally content

2.2. Obtain database information and output html file

#require_once 'coon.php';$sql = "select * from name order by id;";$result = $ link->query($sql);
$arr ​​= array();
while($re = $result->fetch(PDO::FETCH_ASSOC)){
$arr[] = $re;
}
//Loop output content to html file
ob_start(); //Open buffer
?>

The above is the detailed content of Teach you how to use the ob function to output static html files. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
详解JavaScript函数如何实现可变参数?(总结分享)详解JavaScript函数如何实现可变参数?(总结分享)Aug 04, 2022 pm 02:35 PM

js是弱类型语言,不能像C#那样使用param关键字来声明形参是一个可变参数。那么js中,如何实现这种可变参数呢?下面本篇文章就来聊聊JavaScript函数可变参数的实现方法,希望对大家有所帮助!

深入解析C语言中static关键字的作用和用法深入解析C语言中static关键字的作用和用法Feb 20, 2024 pm 04:30 PM

深入解析C语言中static关键字的作用和用法在C语言中,static是一种非常重要的关键字,它可以被用于函数、变量和数据类型的定义上。使用static关键字可以改变对象的链接属性、作用域和生命周期,下面就来详细地解析一下static关键字在C语言中的作用和用法。static变量和函数:在函数内部使用static关键字定义的变量称为静态变量,它具有全局生命周

Go语言中如何输出带有换行符的文本Go语言中如何输出带有换行符的文本Mar 15, 2024 pm 04:15 PM

Go语言是一种现代化、高效且简洁的编程语言,广泛应用于各种领域的软件开发中。在Go语言中,输出带有换行符的文本非常简单,可以通过使用fmt包提供的Println函数实现。下面我们将具体介绍如何在Go语言中输出带有换行符的文本,以及相关的代码示例。在Go语言中,想要输出带有换行符的文本,可以使用fmt包提供的Println函数。Println函数会在输出文本的

PHP中私有静态方法的作用及应用场景PHP中私有静态方法的作用及应用场景Mar 23, 2024 am 10:18 AM

PHP中私有静态方法的作用及应用场景在PHP编程中,私有静态方法是一种特殊的方法类型,它只能在定义它的类内部访问,外部无法直接调用。私有静态方法通常用于类的内部逻辑实现,提供了一种封装和隐藏细节的方式,同时又具有静态方法的特性,可以在不实例化类对象的情况下被调用。下面将探讨私有静态方法的作用及应用场景,并提供具体的代码示例。作用:封装和隐藏实现细节:私有静态

go语言的形参占用内存吗go语言的形参占用内存吗Dec 28, 2022 pm 05:19 PM

形参变量在未出现函数调用时并不占用内存,只在调用时才占用,调用结束后将释放内存。形参全称“形式参数”,是函数定义时使用的参数;但函数定义时参数是没有任实际何数据的,因而在函数被调用前没有为形参分配内存,其作用是说明自变量的类型和形态以及在过程中的作用。

快速掌握静态相对定位的技巧与方法快速掌握静态相对定位的技巧与方法Jan 18, 2024 am 11:18 AM

快速静态相对定位是网页开发中非常重要的一种定位方式。它可以使元素相对于其正常位置进行微调的同时,仍然保持在文档流中的位置。在本文中,我将详细介绍快速静态相对定位的使用方法,以及一些常见的应用场景。首先,我们需要了解快速静态相对定位的基本概念。在CSS中,元素的定位方式有四种:静态定位、相对定位、绝对定位和固定定位。静态定位是默认的定位方式,元素的位置通过文档

go语言中函数是什么意思go语言中函数是什么意思Dec 08, 2022 pm 07:48 PM

在go语言中,函数是组织好的、可重复使用的、用来实现单一具体或相关联功能的代码段(块);其主要目的是提高应用的模块性和代码的重复利用率,更好的管理代码,模块化开发。函数通常使用参数和返回值,与调用者交互数据;参数给函数传递数据,返回值,函数将处理好的数据传递给调用者。

静态重定位技术的原理及其应用案例静态重定位技术的原理及其应用案例Jan 18, 2024 am 11:12 AM

静态重定位技术的原理和应用引言:在现代计算机系统中,内存管理是一个非常重要的课题。随着软件的复杂性和规模的增加,内存的限制成为了我们面临的一个挑战。为了更高效地利用内存资源,静态重定位技术应运而生。本文将介绍静态重定位技术的原理、应用以及提供一些具体的代码示例。一、静态重定位技术的原理静态重定位是一种将程序代码和数据从一个逻辑地址空间移动到另一个逻辑地址空间

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),