note 59278 deleted from function.ucfirst by jacques
| From: | jacques@php.net | Date: | Wed, 28 Dec 2005 14:37:46 +0000 |
| Subject: | note 59278 deleted from function.ucfirst by jacques | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-100853@lists.php.net to get a copy of this message | ||
Note Submitter: dmitry dot polushkin at gmail dot com
----
<?
/**
* Make every word in $str with first letter uppercase.
*
* @param string $str
* @return string
* @author by Solid @2005 (http://dmitry.info)
* @example echo strtoupper_words('herE is some wordS.');
*/
function strtoupper_words($str) {
$str = strtolower($str);
/*
// this method 3 times slower
$flag = true;
for($i=0; $i<strlen($str); $i++) {
if($flag) {
$str[$i] = strtoupper($str[$i]);
}
if($str[$i]==' ') {
$flag = true;
} else {
$flag = false;
}
}
return $str;
*/
$str = explode(' ', $str);
for($i=0, $total=count($str); $i<$total; $i++) {
$str[$i] = ucwords($str[$i]);
//$str[$i][0] = strtoupper($str[$i][0]); // this will work slower
}
return implode(' ', $str);
}
?>