note 105991 modified in function.ucwords by danbrown

From: Date: Fri, 30 Sep 2011 21:43:42 +0000
Subject: note 105991 modified in function.ucwords by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-183576@lists.php.net to get a copy of this message
Because I needed a function that did the same as the function proper in Excel I created this little function : <?php function proper($string){ $string = strtolower($string); $lettersAndNumbers = 'abcdefghijklmnopqrstuvwxyz01234565789'; $string[0] = strtoupper($string[0]); for ($index = 1;$index < strlen($string);$index++){ if (strpos($lettersAndNumbers, $string[$index]) === false){ if ($index +1 < strlen($string)){ $string[$index+1] = strtoupper($string[$index+1]); $index++; } } } return($string); } ?> --was-- Because I needed a function that did the same as the function proper in Excel I created this little function : function proper($string){ $string = strtolower($string); $lettersAndNumbers = 'abcdefghijklmnopqrstuvwxyz01234565789'; $string[0] = strtoupper($string[0]); for ($index = 1;$index < strlen($string);$index++){ if (strpos($lettersAndNumbers, $string[$index]) === false){ if ($index +1 < strlen($string)){ $string[$index+1] = strtoupper($string[$index+1]); $index++; } } } return($string); } http://php.net/manual/en/function.ucwords.php

« previous php.notes (#183576) next »