note 73984 deleted from function.trim by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 12:24:56 +0000 |
| Subject: | note 73984 deleted from function.trim by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189650@lists.php.net to get a copy of this message | ||
Note Submitter: Hayley
----
trim's code can of course be simplified with some use of the trim() function....
<?php
$str = " Words with lots of spaces ";
$str = preg_replace('/\s\s+/', ' ', trim($str));
?>
Doing the trim() first reduces the workload being put on the more expensive preg_replace().