note 77010 deleted from function.trim by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 12:25:11 +0000 |
| Subject: | note 77010 deleted from function.trim by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189653@lists.php.net to get a copy of this message | ||
Note Submitter: Hayley Watson
----
Robin Leffman's code could be improved further...
<?php
$string = 'This string has no whitespaces.';
echo str_replace(' ', '', $string );
?>
Of course, like Leffman's code, that only removes space characters, not necessarily all
whitespace (or characters in some arbitrary $whiteSpace string). For that
<?php
function trimlrm ($hayStack, $whiteSpaceChars)
{
$char = $whiteSpaceChars[0];
$chars = str_repeat($char, strlen($whiteSpaceChars);
$trimmed = strtr($hayStack, $whiteSpaceChars, $chars)));
return str_replace($char, '', $trimmed);
}
?>
would probably work, but like the others, fails to give '..' the same specialness that it
has in trim().