note 29402 rejected from function.strpos by didou

From: Date: Sun, 10 Aug 2003 02:58:27 +0000
Subject: note 29402 rejected from function.strpos by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-53782@lists.php.net to get a copy of this message
Note Submitter: webmaster@wilsoncounty.com ---- There are a couple problems with the function(s) and code above for stripping spaces. The main problem is multiple spaces. For example, if someone entered "this is my answer! !!!". There would still be multiple spaces in the text after using the previously mentioned methods. The solution is to loop until there are no more multiple spaces. Here is my solution ... function StripSpaces ( $inputString ) { $inputString = trim($inputString); $pos = strpos($inputString, " "); while (is_integer($pos) && $pos > 0) { $inputString = str_replace(" ", " ", $inputString); $pos = strpos($inputString, " "); } return $inputString; } Sure, it could have been shorter but it is more readable in this form. Good Luck!!!

« previous php.notes (#53782) next »