Re: running a function on an eregi-substring

From: Date: Wed, 21 May 2003 05:10:17 +0000
Subject: Re: running a function on an eregi-substring
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-148357@lists.php.net to get a copy of this message
preg_replace_callback() can give you what you want preg_* functions are generally preferred to ereg_* === example === function makebold($matches) { return '<b>'.$matches.'</b>'; } $content = 'hello world'; echo $text.'<br>'; $text=preg_replace_callback("/hello/i",'makebold',$text); echo $text.'<br>'; Here's a good quick reference for regular expressions http://builder.cnet.com/webbuilding/pages/Programming/Kahn/050698/ref.html olinux > on 19/05/03 9:53 PM, Michiel van Heusden > (michiel@aemulatio.nl) wrote: > > > i'm having trouble using eregi_replace in a script > similar to the following > > don't if this is possible at all but i'd like to > know if this is possible, > > how to fix it, any help? > > > > <? > > > > $content = "hello world"; > > > > function makebold ($string) { > > return "<b>" . $string . "</b>"; > > } > > > > $output = eregi_replace("hello", makebold(\\0), > $content); > > > > echo $output; > > > > ?> > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > __________________________________ Do you Yahoo!? The New Yahoo! Search - Faster. Easier. Bingo. http://search.yahoo.com

« previous php.general (#148357) next »