Re: preg_replace help please

From: Date: Thu, 25 Sep 2003 01:23:35 +0000
Subject: Re: preg_replace help please
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-163837@lists.php.net to get a copy of this message
Justin French wrote:
this is supposed to any occurrence of *something* into <strong>something</strong> $str = preg_replace("!\*(.*?)\*!"," <strong>\\1</strong>\\2",$str); it works fine on single lines, but it breaks when there's a \n (and perhaps other white spaces?) in the string, eg: *something with a newline* I think this is because .*? doesn't include newlines... can anyopne help me modify the above to work on multiple lines????
Yes, that's the reason. Use an 's' modifier to make the dot character match newlines. It's all in the F manual. :) $str = preg_replace("!\*(.*?)\*!s"," <strong>\\1</strong>\\2",$str); -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.general (#163837) next »