RE: [PHP] Re: template in message string
| From: | Dan Rossi | Date: | Thu, 17 Apr 2003 13:07:19 +0000 |
| Subject: | RE: [PHP] Re: template in message string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144274@lists.php.net to get a copy of this message | ||
hmm i just tried your example , Hello {username} you have changed your pass
to {pass} this returned this Hello - the rest got cut off ?
-----Original Message-----
From: SLanger@spirit21.de [mailto:SLanger@spirit21.de]
Sent: Thursday, April 17, 2003 5:15 PM
To: daniel@electroteque.org
Cc: php-general@lists.php.net
Subject: Re: [PHP] Re: template in message string
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