PHP static file generation class instance

Source: Internet
Author: User
This article mainly introduces the PHP static file generation class. It demonstrates the PHP static file generation method in the form of an instance and encapsulates it into class files for ease of use. It is a very practical technique, for more information, see

This article mainly introduces the PHP static file generation class. It demonstrates the PHP static file generation method in the form of an instance and encapsulates it into class files for ease of use. It is a very practical technique, for more information, see

This example describes the PHP static file generation class. Share it with you for your reference.

The specific implementation code is as follows:

The Code is as follows:

<? Php
Class CreateHtml
{
Function mkdir ($ prefix = 'Article ')
{
$ Y = date ('y ');
$ M = date ('M ');
$ D = date ('D ');
$ P = DIRECTORY_SEPARATOR;
$ FilePath = 'Article'. $ p. $ y. $ p. $ m. $ p. $ d;
$ A = explode ($ p, $ filePath );
Foreach ($ a as $ dir)
{
$ Path. = $ dir. $ p;
If (! Is_dir ($ path ))
{
// Echo 'This directory does not exist'. $ path;
Mkdir ($ path, 0755 );
}
}
Return $ filePath. $ p;
}
Function start ()
{
Ob_start ();
}
Function end ()
{
$ Info = ob_get_contents ();
$ FileId = '000000 ';
$ Postfix = '.html ';
$ Path = $ this-> mkdir ($ prefix = 'Article ');
$ FileName = time (). '_'. $ fileId. $ postfix;
$ File = fopen ($ path. $ fileName, 'w ');
Fwrite ($ file, $ info );
Fclose ($ file );
Ob_end_flush ();
}
}
?>


The usage is as follows:

The Code is as follows:

<? Php
$ S = new CreateHtml ();
$ S-> start ();
?>


Asdfasdfasdfasdfasdfasdfasdfasdfasdfasdf

Adfasdfasdf

>

<? Php
$ S-> end ();
?>

I hope this article will help you with PHP programming.

,

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.