Home  >  Article  >  Backend Development  >  Two kinds of PHP generated HTML page implementation code_PHP tutorial

Two kinds of PHP generated HTML page implementation code_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:54:39815browse

Two php tutorials to generate html page implementation code

Use fopen fread fwrite fcolse to open the file format

$fp = fopen ("templets.html","a");
if ($fp){
$fup = fread ($fp,filesize("templets.html"));
$fp2 = fopen ("html.shtml","w");
if ($fwrite ($fp2,$fup)){
$fclose ($fp);
$fcolse ($fp2);
die ("Write template successfully");
} else {
fclose ($fp);
die ("Failed to write template!");
}
}
?>

PHP reads files, fread is used to read the contents of files opened with fopen, let’s take a look at the fread and gets example tutorial.

Definition and usage
The fread() function reads a file (safe for use with binary files).

Grammar
fread(file,length) parameter description
file required. Specifies that the file should be opened for reading.
length required. Specifies the maximum number of bytes to read.

Description
fread() reads up to length bytes from the file pointer file. This function reads up to length bytes, or when eof is reached, or (for network streams) when a packet is available, or (after opening a user space stream) when 8192 bytes have been read. Will stop reading the file, depending on which condition is encountered first.

$file = fopen("test.txt","r");
fread($file,filesize("test.txt"));
fclose($file);
?>


For more details, please check: http://www.bKjia.c0m/phper/18/753bc9c01fa5a721a81c63887ddccb47.htm

Cache output ob_end_clean ob_start ob_get_length ob_get_contents function

$s_fname = "93e.php";
$o_fname = "93e.htm";
ob_end_clean();
ob_start();
include($s_fname);
$length = ob_get_length();
$buffer = ob_get_contents();
$buffer = eregi_replace("r","",$buffer);
ob_end_clean();

$fp = fopen($o_fname,"w+");
fwrite($fp,$buffer);
fclose($fp);
?>


Three functions: "ob_start(), ob_end_clean(), ob_get_contents()"

ob_start(): opens the buffer, which is to cache the content of the static file you need to generate here;
ob_get_contents(): reads the contents in the buffer. The following code is an example;
ob_end_clean(): This is more important. Only after using this function can the content in the buffer be read

For more details, please check: http://www.bKjia.c0m/phper/php-cy/35433.htm

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631729.htmlTechArticleTwo php tutorials to generate html page implementation code using fopen fread fwrite fcolse to open the file form?php $fp = fopen ( templets.html,a); if ($fp){ $fup = fread ($fp,filesize(templets.html...
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