note 70593 added to function.strtoupper
| From: | myemailistrucexanditsatgmail at osu1 dot php dot net | Date: | Sat, 21 Oct 2006 01:55:35 +0000 |
| Subject: | note 70593 added to function.strtoupper | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-118886@lists.php.net to get a copy of this message | ||
There are a lot of lengthy examples on doing proper case. If you just need to have the first letter
of the string capitalized and the rest lower case, just do this:
<?php
$string = strtolower($string);
$string = substr_replace($string, strtoupper(substr($string, 0, 1)), 0, 1);
?>
If you need to have all the words in a sentence like that, just set it up like this:
<?php
$words = explode(" ", $string);
for($i=0; $i<count($words); $i++) {
$string = strtolower($words[$i]);
$string = substr_replace($string, strtoupper(substr($string, 0, 1)), 0, 1);
$pString .= "$string ";
}
?>
Obviously, you will have a bit more work ahead of you if you want to do anything fancy, but I
didn't need anything fancy and I know there are thousands of applications that don't need
anything fancy, so keeping it simple works better. :)
----
Server IP: 216.194.113.175
Probable Submitter: 69.252.131.134
----
Manual Page -- http://www.php.net/manual/en/function.strtoupper.php
Edit -- https://master.php.net/note/edit/70593
Del: integrated -- https://master.php.net/note/delete/70593/integrated
Del: useless -- https://master.php.net/note/delete/70593/useless
Del: bad code -- https://master.php.net/note/delete/70593/bad+code
Del: spam -- https://master.php.net/note/delete/70593/spam
Del: non-english -- https://master.php.net/note/delete/70593/non-english
Del: in docs -- https://master.php.net/note/delete/70593/in+docs
Del: other reasons-- https://master.php.net/note/delete/70593
Reject -- https://master.php.net/note/reject/70593
Search -- https://master.php.net/manage/user-notes.php