Re: running a function on an eregi-substring
| From: | David Otton | Date: | Mon, 19 May 2003 18:31:08 +0000 |
| Subject: | Re: running a function on an eregi-substring | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-148193@lists.php.net to get a copy of this message | ||
On Mon, 19 May 2003 13:17:17 +0200, you wrote:
>----- Original Message -----
>From: "David Otton" <phpmail@jawbone.freeserve.co.uk>
>To: "Michiel van Heusden" <michiel@aemulatio.nl>
>Cc: <php-general@lists.php.net>
>Sent: Monday, May 19, 2003 1:16 PM
>Subject: Re: [PHP] running a function on an eregi-substring
>> On Mon, 19 May 2003 12:53:37 +0200, you wrote:
>> Having a hard time seeing what you're trying to do. You want your output
>> string to look like this?
>>
>> <b>hello world</b>
>>
>> $output = makebold($content);
>>
>> Or like this?
>>
>> <b></b> world
>>
>> $output = eregi_replace ("hello", makebold(""), $output);
>it should be like:
>$output = "<b>hello</b> world";
>but it's just an example, the actual purpose is a bit too complicated to
>explain
>it's about running the function on the part that eregi takes out..
Ah.... I see. Sounds like you want a callback...
There isn't a POSIX-regex function to do this. You need to use
preg_replace_callback() instead.
http://www.php.net/manual/en/function.preg-replace-callback.php
Lets see....
function makeBold($matches) {
return('<b>' . $matches[0] . '</b>');
}
$t = "hello world";
echo(preg_replace_callback("(hello)", "makeBold", $t));
Let me know if that works for you.