亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home PHP Libraries Other libraries PHP template parsing class
PHP template parsing class
<?php
class Parser
{
  private $_tpl;
  public function __construct($_tplFile)
  {
    if (! $this->_tpl = file_get_contents($_tplFile)) {
      exit('ERROR:模版文件讀取錯(cuò)誤');
    }
  }
  private function parvar()
  {
    $_patten = '/<!--\s+\{$([\w]+)\}\s+-->/';
    if (preg_match($_patten,$this->_tpl)) {
      $this->_tpl = preg_replace($_patten, "<?php echo $this->_vars[''];?>",$this->_tpl);
    }
  }
  private function parif(){
    $_pattenif = '/<!--\s+\{if\s+$([\w]+)\}\s+-->/';
    $_pattenElse = '/<!--\s+\{else\}\s+-->/';
    $_pattenEndif = '/<!--\s+\{\/if\}\s+-->/';
    if (preg_match($_pattenif,$this->_tpl)) {
      if (preg_match($_pattenEndif,$this->_tpl)) {
        $this->_tpl = preg_replace($_pattenif,"<?php if ($this->_vars['']){?>",$this->_tpl);
        $this->_tpl = preg_replace($_pattenEndif,"<?php } ?>",$this->_tpl);
        if (preg_match($_pattenElse,$this->_tpl)) {
          $this->_tpl = preg_replace($_pattenElse,"<?php }else{?>",$this->_tpl);
        }
      }else{
        echo 'ERROR:IF語(yǔ)句沒(méi)有關(guān)閉!';
      }
    }
  }

After receiving the content of the template file, construct a method, obtain the content of the template file and parse it, use ordinary variables to parse the IF statement, and then parse the template file to generate a compiled file.

Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

How Do I Link Static Libraries That Depend on Other Static Libraries? How Do I Link Static Libraries That Depend on Other Static Libraries?

13 Dec 2024

Linking Static Libraries to Other Static Libraries: A Comprehensive ApproachStatic libraries provide a convenient mechanism to package reusable...

Why Do PHP Developers Use Leading Underscores in Class Methods? Why Do PHP Developers Use Leading Underscores in Class Methods?

11 Nov 2024

Hidden Truths: The Leading Underscore in PHP Class MethodsWhen browsing PHP libraries, one might stumble upon class methods prefixed with a...

Why Do Some PHP Class Methods Start with an Underscore? Why Do Some PHP Class Methods Start with an Underscore?

09 Nov 2024

Why Do Some PHP Class Methods Begin with an Underscore?While exploring PHP libraries, you might have noticed that certain developers prefer to...

C   class template specialization C class template specialization

07 Jul 2025

Class template specialization is a technique that provides completely different class template implementations for specific types. Its core uses include: 1. Performance optimization, such as bypassing redundant logic for types such as int, char*; 2. Type adaptation, and handling type logic with large differences; 3. Compatibility processing, such as distinguishing pointer and reference types. Fully specialization specifies all parameter types, while partial specialization specifies only some parameters or constraints, and is only applicable to class templates. Note when writing: specialized class bodies must be fully defined, avoid repeated definitions, and prioritize matching of the most specific version.

Why is my typedef in a base class template inaccessible in my derived class template? Why is my typedef in a base class template inaccessible in my derived class template?

09 Dec 2024

Unrecognized Typedef in Derived Class TemplateWhen declaring a derived class template B that inherits from a base class template A, it's expected...

Does PHP Offer a BigInteger Class for Large Integer Handling? Does PHP Offer a BigInteger Class for Large Integer Handling?

21 Oct 2024

BigInteger Class in PHPDoes PHP include a BigInteger class for handling large integers? If so, how is it accessed and utilized?Answer:While PHP does not natively include a BigInteger class, external libraries can provide this functionality. Two notab

See all articles