|
|
 |
ucfirst (PHP 3, PHP 4 , PHP 5) ucfirst -- Make a string's first character uppercase Descriptionstring ucfirst ( string str)
Returns a string with the first character of
str capitalized, if that character is
alphabetic.
Note that 'alphabetic' is determined by the current locale. For
instance, in the default "C" locale characters such as umlaut-a
(ä) will not be converted.
例子 1. ucfirst() example |
<?php
$foo = 'hello world!';
$foo = ucfirst($foo); // Hello world!
$bar = 'HELLO WORLD!';
$bar = ucfirst($bar); // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
?>
|
|
See also strtolower(), strtoupper(),
and ucwords().
bkimble at ebaseweb dot com
09-Jun-2003 08:02
Here is a handy function that makes the first letter of everything in a
sentence upercase. I used it to deal with titles of events posted on my
website ... I've added exceptions for uppercase words and lowercase words
so roman numeral "IV" doesn't get printed as "iv" and
words like "a" and "the" and "of" stay
lowercase.
function RemoveShouting($string) {
$lower_exceptions = array( "to" => "1",
"a" => "1", "the" => "1",
"of" => "1" );
$higher_exceptions = array( "I" =>
"1", "II" => "1", "III" =>
"1", "IV" => "1", "V"
=> "1", "VI" => "1", "VII"
=> "1", "VIII" => "1",
"XI" => "1", "X" => "1"
);
$words = split(" ", $string); $newwords = array();
foreach ($words as $word) { if
(!$higher_exceptions[$word]) $word =
strtolower($word); if (!$lower_exceptions[$word])
$word = ucfirst($word); array_push($newwords, $word);
} return join(" ", $newwords); }
| |