PHP generates static page classes

Source: Internet
Author: User

<?php
Date_default_timezone_set ("Asia/shanghai");

Class tcreatehtml{
var $HTemplate; Files for templates
var $FileName; New file name
var $HTFilePath//path to generate file
var $ModiString;
var $ReTextArray;//substitution Information array
var $strText = ""; Text content
var $CrType = "1"; The type that produces the file name defaults to the date + 4-bit random number
var $errorStr; Error message!

interface functions
Construct template
function tcreatehtml () {}

Create a file
function creatrhtml ()
{
Check that the template path is legitimate
if (! $this->checkpath ($this->htemplate, "0"))
{
return false;
}

Check to see if the new file path is legitimate
if (! $this->checkpath ($this->htfilepath, "1"))
{
return false;
}


$FP =fopen ($this->htemplate, "R"); Read-only open template
$this->strtext=fread ($fp, FileSize ($this->htemplate));//Read the contents of the template
Fclose ($FP);

Replace file
$this->replacetext ();
Generate file name
$this->createname ();


$handle =fopen ($this->filename, "w"); Write way to open a news path
Fwrite ($handle, $this->strtext); Write what you just replaced into the generated HTML file
Fclose ($handle);

return true;
}

function Checkpath ($PSTR, $type)
{
if ($type = = "0")
{
if (!file_exists ($PSTR))
{
$this->errorstr= "folder path is wrong!";
return false;
}
}else
{
$arrPath = Explode ("/", $PSTR);
$s _path= "";
foreach ($arrPath as $tag) {
if ($s _path== "")
{
$s _path. = $tag;
}else
{
$s _path. = "/". $tag;
}

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.