This article is quoted from network
First introduce your own file class:
<?php
/**
* File Processing class
*/
Class Files
{
Private $resource = null; File resource handle
function __construct ($fileName, $mode = ' R ')
{
$dirName = DirName ($fileName);//file path
$baseName = BaseName ($fileName);//File name
Check and create a folder
Self::mkdir ($dirName);
$this->resource = fopen ($fileName, $mode. ' B ');
if ($this->resource)
{
Flock ($this->resource,lock_ex);//Lock-in
}
}
File Write function
Public function write ($content)
{
$worldsnum = fwrite ($this->resource, $content);
Return Is_bool ($worldsnum)? False: $worldsnum;
}
}
Write a function to generate a static file:
Private Function writehtml ($path, $content) {
if (! class_exists (' Files ')) {
$this-Load->file (APPPATH. ' Libraries/files '. EXT);//I use the CI framework, introduce the file class here to make a slight change
$f = new Files ($path, ' w+ ');
$res = $f->write ($content);
$f->save ();
}
Finally call the above function where you need to generate a static page:
function crativehtml{
$url = "php dynamic file path";
$content = file_get_contents ($url);//Get File contents
$this-_writefile ($path. ' File name. html ', $content);
}
Just such a static file is generated, the last file can be written in multiple places to generate different static files,
PHP generates static files