note 54445 deleted from function.preg-replace by didou
| From: | didou@php.net | Date: | Sun, 23 Apr 2006 22:49:17 +0000 |
| Subject: | note 54445 deleted from function.preg-replace by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109224@lists.php.net to get a copy of this message | ||
Note Submitter: M. Kristall
----
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.)