Web page Template Generation class

Source: Internet
Author: User

Web page Template Generation class
<?php
/*
Web page Template Generation class
Use: Mainly used for the generation of static resource surface pages. This class also applies to the generation of static pages for other systems
Invoke instance:
$TPL = new Templateengine ();
$tpl->opentemplate ("e:/t.htm");
$tpl->startelement = "<!--resource Title identification-Start-->";
$tpl->endelement = "<!--resource title identification-end-->";
$tpl->value = "This is the replacement content of the title of the resource";
$tpl->replacetemplate ();
$tpl->save ();
*/

The hidden contents of this post need to reply before you can browse
Class Templateengine
{
Public $filepath, $startelement, $endelement, $value;
Private $template, $fso, $fle, $regex, $filestate;

Function __construct ()
{
  $this->filestate = false;
  $this->filepath  = ';
&nb Sp $this->template  = ';
  $this->startelement = ';
  $this->endelement = ';
}
Private Function Filterstr ($str)
{
  if ($str = = ' | | is_null ($STR)) return ';
//  $str = s Tr_replace (', ' \ ', $str);
  $STR = str_replace ('/', '/', $str);
  $STR = Str_replace (' (, ', ', $str);
  $STR = str_replace (') ', ') ', $str);
  $STR = Str_replace (' * ', ' * ', $str);
  $STR = Str_replace ('? ', '? ', $str);
  $STR = Str_replace (' {', '} ', $str);
  $STR = Str_replace ('} ', ' {', $str);
  $STR = Str_replace ('. ', '. ', $str);
  $STR = str_replace (' + ', ' + ', $str);
  $STR = Str_replace (' [', ' [', $str];
  $STR = Str_replace ('] ', '] ', $str);
  return $str;
}

//Set template file path
Public function opentemplate ($mfilepath)
{
  global $flib;
  if (!) ( $this->template= @file_get_contents ($mfilepath)) {$flib->alert (' specified template file does not exist! ', ' back ', 0); exit ();}
  $this->filestate = true;
  $this->filepath = $mfilepath;
}
//Determine if the identity exists
Public Function iselement ()
{
  if (! $this->filestate | | $this->template== ' || $this->startelement== ' | | $this->endelement== ') return;
  $STRPATRN = "/". $this->filterstr ($this->startelement). " [ss]*?] $this->filterstr ($this->endelement). " /";
  return Preg_match ($STRPATRN, $this->template)? 1:0;
}

//change template elements, element tags in general format: "<!-element tag-start--><!--element tag-end-->", you can also customize
   //Element label is case-insensitive
Public Function replacetemplate ()
{
  if (! $this->filestate | | $this->template== ' | | $this-> startelement== ' ' | | $this->endelement== ') return;
  $STRPATRN = "/". $this->filterstr ($this->startelement). " [ss]*?] $this->filterstr ($this->endelement). " /";
  $this->template = Preg_replace ($strpatrn, $this->startelement. $this->value. $this-> EndElement, $this->template);
}
///Save new template content
Public function Save ()
{
  if (! $this->filestate) return;
 
  @ File_put_contents ($this->filepath, $this->template);
}
//Save template Content
Public function saveas ($mfilepath)
{
  if (! $this->filestate) return;
  @ File_put_contents ($mfilepath, $this->template);
}
}
?

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.