Re: Passing regexp substrings to a function
| From: | Robin Vickery | Date: | Tue, 26 Oct 2004 12:30:36 +0000 |
| Subject: | Re: Passing regexp substrings to a function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-200337@lists.php.net to get a copy of this message | ||
On Mon, 25 Oct 2004 15:33:59 +0300, Ville Mattila
<ville.mattila@pilotmedia.fi> wrote:
> Hi there,
>
> I have a few e-mail templates in a file that should be parsed. A
> template can include also some "module codes" that should be replaced by
> a return value of a certain function. For example, if the template
> include a text "{ProductInfo:1032}", the value 1032 would be passed as
> an argument to a function mdlProductInfo() and the whole string would be
> replaced by the return value of the function.
>
> One possible way is to loop the string like this:
> [...]
> Any other ideas on this?
Yeah, use preg_replace_callback() , it does exactly what you're suggesting.
http://fi.php.net/manual/en/function.preg-replace-callback.php
-robin