Re: Passing regexp substrings to a function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

In perl, you can do something like:

$string =~ s/---piece of text that contains a certain (VALUE) in
it---/&function($1)/gse;

This expression replaces its first part with the result of the function
"function" called with the parameter "VALUE".
Is this what you want?

Maybe you can do something like that  using perl regular expressions in
PHP...

Teddy

----- Original Message ----- 
From: "Ville Mattila" <ville.mattila@xxxxxxxxxxxxx>
To: "PHP General Mailing List" <php-general@xxxxxxxxxxxxx>
Sent: Monday, October 25, 2004 2:33 PM
Subject:  Passing regexp substrings to a function


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:

while(eregi("{([a-z])(:[a-z0-9])+}", $template, $regs)) {
list($whole, $function, $valuestring) = $regs;
$values = explode(":", substr($valuestring, 1));

unset($retval);
eval("$retval = mdl".$function."(".join(",", $values).");");

$template = str_replace($whole, $retval, $template);
}

Any other ideas on this?

Ville

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux