note 54445 added to function.preg-replace

From: Date: Mon, 04 Jul 2005 23:55:18 +0000
Subject: note 54445 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-91444@lists.php.net to get a copy of this message
Karl Kangur, You can also use the "s" switch on your RE to treat new lines as part of the same line. For example, <?php $string = " once upon a time"; echo preg_replace ( array ( '/\s+/s', // Any space(s) '/^\s+/s', // Any space(s) at the beginning '/\s+$/s' // Any space(s) at the end ), array ( ' ', // ... one space '', // ... nothing '' // ... nothing ), $string ); // outputs 'once upon a time' ?> (Note: php.net uses non-breaking spaces followed by spaces, repetitively. Browsers ignore multiple white space - one nbsp counts as a space, so unless the next one is also an nbsp, it is ignored. <pre>...</pre> could be used in this case thus solving the problem and removing any need for nbsp at all.) ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54445 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54445&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54445&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54445&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54445&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54445&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54445&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54445&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91444) next »