|
Posted by Yorian on 02/25/07 19:25
I just started to try regexps in php and I didn't have too many
problems, however I found a few when trying to build a templte engine.
The first one is found is the dollar sign. In my template I would like
to write this:
{$var} where var ofcourse will be replaced by the real var however I'm
having trouble with the dollar sign I do escape the it though, my
regexp:
preg_replace("/\{\$(.+?)\}/", 'var', $string);
However this didn't work, even if I try to just replace the dollar
sign (by a b) it doesn't work properly:
preg_replace("/\$/", "b", $string);
Another question is about lookaheads/behinds, in my template I would
like to use this:
{include file="file.tpl"} for example, so I created this regexp:
preg_replace("/\{include file=(?:\"|\')*(.+?)(?:\"|\')*\}/i",
'replacement', $string);
Works fine but now people don't have to use the same opening and
ending character, how do I do that?
Last questions for now, I know regexps are not very fast and this does
give a bit of a problem.
So my questions:
- Are there things in regexps te be avoided since it takes ages?
- Are there ways to speed up regexps?
Navigation:
[Reply to this message]
|