Reply to Re: [PHP] A couple questions about templating

Your name:

Reply:


Posted by Rory Browne on 05/10/05 02:46

> I am trying to make a small, fast, and simple templating class... Now
> I have mastered the art of variable replacement, and have made two
> versions. The first one I made simply used file() to load up the file
> into an array,
Personally I think you should use file_get_contents() instead.

> str_replace() to replace variables, then it printed it
> back.
Unless you're doing only very basic substitution, you may need to
consider regex, and preg_replace().

> I made a second one, which reads the file into an array,
> changes the variables the same way, but instead compiles the finished
> product into a compile directory and then reads the compiled file back
> to the page. the benefit to this being that I can easily create a
> simple cache system now.

All I'd change here, is that instead of reading the file into an
array, I'd load it into a string.

> 1st question) I need a professionaly opinion on to which solution is
> better, considering speed, security, and expandability.
Depends on how it's implemented. When you 'compile' the script into
native php, you are having a highly optimised parser do the variabe
insertion. Your main problem here would be register_globals, so you
need to ensure that you initialise any variables used.

> 2nd question) Like I said before, I've mastered the art of variable
> replacement, but how would one go about adding support for if {}
> statements as well as loops. I'm a little bit lost when it comes to
> this.
You could use a full featured tokeniser/parser(and you'd probably IIRC
find one in Pear), but it may perhaps be simpler, to simply use preg
to replace something like {foreach:var:list}, or whatever your
perfered syntax.

> Thank-you guys very very much.
> --
> jamwil.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация