Re: Another preg question

From: Date: Sun, 15 Feb 2004 21:38:54 +0000
Subject: Re: Another preg question
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-177750@lists.php.net to get a copy of this message
Thanks for the feedback. Here was my problem; I misunderstood how the "+" worked. It only applies to the last "\n", not both "n\n". Hans Juergen Von Lengerke wrote:
From: Al <news@ridersite.org> $text= preg_replace("/\n\n+/", "\n\n", $text); // remove excess This doesn't seem to do anything.
Strange, your code works for me: hj@spirit:~ > cat foo.php <?php $text = "foo\n\n\n\n\nbar"; echo "before:\n===\n$text\n===\n\n"; $text = preg_replace("/\n\n+/", "\n\n", $text); echo "after:\n===\n$text\n===\n\n"; ?> hj@spirit:~ > php ./foo.php before: === foo bar === after: === foo bar === hj@spirit:~ > php -v PHP 4.3.4 (cli) (built: Feb 12 2004 17:42:41) Copyright (c) 1997-2003 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies hj@spirit:~ >


« previous php.general (#177750) next »