note 87947 deleted from function.trim by danbrown

From: Date: Thu, 01 Jan 2009 17:18:26 +0000
Subject: note 87947 deleted from function.trim by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-148743@lists.php.net to get a copy of this message
Note Submitter: info at deep-soft dot com Reason: integrated ---- there is a mistake in "josecruz at josecruz dot com dot br" function: it deletes the first char after spaces (because of while). here is the correct function: <?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; } ?>

« previous php.notes (#148743) next »