note 87164 deleted from function.trim by peehaa
| From: | peehaa@php.net | Date: | Tue, 21 Mar 2017 08:42:14 +0000 |
| Subject: | note 87164 deleted from function.trim by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208928@lists.php.net to get a copy of this message | ||
Note Submitter: josecruz at josecruz dot com dot br
----
A simple function to clear extra white spaces along a string.
<?php
function TrimStr($str)
{
$str = trim($str);
for($i=0;$i < strlen($str);$i++)
{
if(substr($str, $i, 1) != " ")
{
$ret_str .= trim(substr($str, $i, 1));
}
else
{
while(substr($str,$i,1) == " ")
{
$i++;
}
$ret_str.= " ";
$i--; // ***
}
}
return $ret_str;
}
?>
[EDIT BY danbrown AT php DOT net: Contains a fix provided by (info AT deep-soft DOT com) to address
the issue where "it deletes the first char after spaces (because of while)."]