0

i built php class for parsing html templates , and i used preg_replace_callback function for parsing template while loops & if conditions , for loop , ... etc

i repeated the function many times , for every process , such as one time for parsing while loop , and another time for if conditions parsing .. etc , and repeated all of these steps again when parsing include files inside the template ,

but i think that this method of parsing is slow when parsing big template ,

so i think that using one while loop and read template line by line and compare it then parsing found line will be more fast ,

so what is your opinion , using one while loop and read the template file line by line and parsing it is more useful ? or using preg_replace_callback ?

and is it preferred to parse the codes inside the template ? by replacing it with php code then evaluate the template using eval() ? or parsing it inside the php file then append the result to the template ?

Jason4Ever
  • 1,439
  • 4
  • 23
  • 43
  • Why don't you use PHP code in template and include it? So you wouldn't have to parse – kero Apr 03 '13 at 20:53
  • If performance is your concern, and you want templates with logic, write raw PHP or use one of the open source templating systems. They will properly tokenize your template and create cache files which are basically a representation of your template in PHP. It would not be cost (time)-effective for you to reinvent the wheel here – Colin M Apr 03 '13 at 20:54
  • What exactly makes you think that this is slower than using a while loop and parsing the template line by line? Any references? – Michael Härtl Apr 03 '13 at 21:19
  • 1
    i tested it on big template, and used another class template use while loop in parsing , the result was that while loop in parsing was faster , also i take a look on RainTPL and Smarty , they don't use preg_replace_callback – Jason4Ever Apr 03 '13 at 21:38

0 Answers0