16 Nov 2007 at 19:47 #1 Immsy Immsy Associate Joined 18 Oct 2002 Posts 2,367 Hi I am building a small attachments system and am wanting to search a string for all instances of
16 Nov 2007 at 20:43 #2 Augmented Augmented Soldato Joined 18 Oct 2002 Posts 5,464 Location London Town You can use the e modifier to run a function on matches with preg_replace: Code: $str = preg_replace("|\[b\](.*?)\[/b\]|e", "'<b>'.strtoupper('\\1').'</b>'", $str); // $str = [ b]foobar[/b ] // output is <b>FOOBAR</b> http://uk2.php.net/preg_replace#id3413129 Or preg_replace_callback() for an alternative method. Last edited: 16 Nov 2007
You can use the e modifier to run a function on matches with preg_replace: Code: $str = preg_replace("|\[b\](.*?)\[/b\]|e", "'<b>'.strtoupper('\\1').'</b>'", $str); // $str = [ b]foobar[/b ] // output is <b>FOOBAR</b> http://uk2.php.net/preg_replace#id3413129 Or preg_replace_callback() for an alternative method.
17 Nov 2007 at 18:41 #3 Immsy Immsy Associate OP Joined 18 Oct 2002 Posts 2,367 Thanks for the reply. I used preg_replace_callback in the end and it does exactly what I need