Re: preg_replace question

From: Date: Fri, 10 Sep 2004 00:38:13 +0000
Subject: Re: preg_replace question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-196273@lists.php.net to get a copy of this message
Zoran Lorkovic wrote:
Sorry for issuing this again, but I need help with preg_replace. I manage to replace certain text between <b></b> in text with preg_replace but I want for every other <b></b> to be replaced by other text. By this I mean when some text between <b></b> has been found that text is replaced with some Text, on second match, text between <b></b> is replaced by some other different text etc. Btw, where I can find patterns that are valid? (something like (\w+), (\d+)+i etc.
Use preg_replace_callback() with a static variable within the callback function. Increment the variable each time the function is called and then based upon whether it's odd or even, substitute the appropriate string. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.general (#196273) next »