note 112442 added to function.str-replace
| From: | cmbecker69 at gmx dot de | Date: | Mon, 17 Jun 2013 01:53:37 +0000 |
| Subject: | note 112442 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-195251@lists.php.net to get a copy of this message | ||
To collapse multiple consecutive space characters to a single one, don't use str_replace()
inside a loop--use preg_replace() instead for clarity and better performance:
<?php
$str = ' This is a test ';
$str = preg_replace('/ +/', ' ', $str);
?>
----
Server IP: 213.172.110.14
Probable Submitter: 95.89.137.54
----
Manual Page -- http://php.net/manual/en/function.str-replace.php
Edit -- https://master.php.net/note/edit/112442
Del: integrated -- https://master.php.net/note/delete/112442/integrated
Del: useless -- https://master.php.net/note/delete/112442/useless
Del: bad code -- https://master.php.net/note/delete/112442/bad+code
Del: spam -- https://master.php.net/note/delete/112442/spam
Del: non-english -- https://master.php.net/note/delete/112442/non-english
Del: in docs -- https://master.php.net/note/delete/112442/in+docs
Del: other reasons-- https://master.php.net/note/delete/112442
Reject -- https://master.php.net/note/reject/112442
Search -- https://master.php.net/manage/user-notes.php