bobleny Posted April 17, 2007 Share Posted April 17, 2007 Is there a way to take a variable such as: $j = "bob"; and turn it into $j = "Bob"; Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/47393-solved-does-php-have-a-capitalization-function/ Share on other sites More sharing options...
utexas_pjm Posted April 17, 2007 Share Posted April 17, 2007 http://us2.php.net/ucwords Quote Link to comment https://forums.phpfreaks.com/topic/47393-solved-does-php-have-a-capitalization-function/#findComment-231206 Share on other sites More sharing options...
bobleny Posted April 17, 2007 Author Share Posted April 17, 2007 ... OK, how do I turn this: $j = "bob will win!" into: $j = "Bob will win!" or into this: $j = "boB will Win!" Quote Link to comment https://forums.phpfreaks.com/topic/47393-solved-does-php-have-a-capitalization-function/#findComment-231208 Share on other sites More sharing options...
jitesh Posted April 17, 2007 Share Posted April 17, 2007 ucfirst (PHP 3, PHP 4, PHP 5) ucfirst -- Make a string's first character uppercase Description string 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. Example 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! ?> ------------------------------------------------- ucwords (PHP 3 >= 3.0.3, PHP 4, PHP 5) ucwords -- Uppercase the first character of each word in a string Description string ucwords ( string str ) Returns a string with the first character of each word in str capitalized, if that character is alphabetic. The definition of a word is any string of characters that is immediately after a whitespace (These are: space, form-feed, newline, carriage return, horizontal tab, and vertical tab). Example 1. ucwords() example <?php $foo = 'hello world!'; $foo = ucwords($foo); // Hello World! $bar = 'HELLO WORLD!'; $bar = ucwords($bar); // HELLO WORLD! $bar = ucwords(strtolower($bar)); // Hello World! ?> Quote Link to comment https://forums.phpfreaks.com/topic/47393-solved-does-php-have-a-capitalization-function/#findComment-231209 Share on other sites More sharing options...
bobleny Posted April 17, 2007 Author Share Posted April 17, 2007 jitesh, yeah, I read that too! No big deal. I really only need ucfirst(). Quote Link to comment https://forums.phpfreaks.com/topic/47393-solved-does-php-have-a-capitalization-function/#findComment-231211 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.