View Full Version : calling functions in ereg()

12-10-2003, 05:56 PM
this will match "[name=coffeedemon]" and i want to attempt it to call a function "displayName()" with coffeedemon as the argument. Can i do this?


displayName() is something along the lines of

function displayName($name)
// name
$newName = ereg_replace('('. $name .')', "<a href=\"http://\\1.domain.com/\">\\1</a>", $name);

$result = $newName;

return $result;

12-10-2003, 07:30 PM
I think you're reaching beyond the capabilities of ereg_replace() in this context. The ereg_* functions are very basic regex functions compared to the much more powerful preg_* functions.

In your case, you can accomplish that by using either preg_replace() and the "e" modifier in your regex, or by calling preg_replace_callback().

For the first possibility, got the documentation page (http://us2.php.net/manual/en/function.preg-replace.php) and look at example 4 to get an idea how the "e" modifier should be used.

The second possibility is more straightforward to use IMO, because it doesn't rely on those cryptic modifiers. Take your pick.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum