Re: Re: template in message string
| From: | SLanger at spirit21 dot de | Date: | Thu, 17 Apr 2003 07:15:12 +0000 |
| Subject: | Re: Re: template in message string | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-144230@lists.php.net to get a copy of this message | ||
Hello
Look at the posting to "preg_replace brain teaser" for a faster way of
doing it.
Also you can use preg_replace with the /e modifier that way you don't have
to use eval! Even faster is preg_replace_callback see the earlier posting.
Also your regex is faulty '/{(.+?)}/'. The { and } should be escaped since
they are metacharacters. so it should read "/\\{(.+?)\\}/".
The double \\ will result in a \ in the final regex since PHP uses \ as a
metacharacter in strings.
Do you really want all characters to appear in the {}? This could lead to
unexpected results with your backreference used as a variable.
Example:
{$myvar} will result in $myvar being matched so what is evaluated later is
actually something like "Message $$myvar" which is definetly not what you
want.
Use something like \w+ to only allow wordcharacters or even better build
your own characterclass that actually contains all allowed characters such
as
[a-zA-Z0-9_-] This will only allow legal characters for php variables.
Regards
Stefan Langer