eggerda Posted May 20, 2009 Share Posted May 20, 2009 Hi, I'm brand new to PHP. I've got a variable called "$name" and it contains a persons first name and last name. All I want is the first name of the person with the first letter capitalized. How do I do that? Thanks, Dan Link to comment https://forums.phpfreaks.com/topic/158859-simple-php-string-operation/ Share on other sites More sharing options...
Prismatic Posted May 20, 2009 Share Posted May 20, 2009 <?php // Our name $name = "john Doe"; // Seperate the name at the space, this will // give us an array with 2 values $parts = explode($name); // ucfirst makes the first character uppercase echo ucfirst($parts[0]); ?> Link to comment https://forums.phpfreaks.com/topic/158859-simple-php-string-operation/#findComment-837884 Share on other sites More sharing options...
Masna Posted May 20, 2009 Share Posted May 20, 2009 <?php // Our name $name = "john Doe"; // Seperate the name at the space, this will // give us an array with 2 values $parts = explode($name); // ucfirst makes the first character uppercase echo ucfirst($parts[0]); ?> Should be: <?php // Our name $name = "john Doe"; // Seperate the name at the space, this will // give us an array with 2 values $parts = explode(" ", $name); // ucfirst makes the first character uppercase echo ucfirst($parts[0]); ?> Link to comment https://forums.phpfreaks.com/topic/158859-simple-php-string-operation/#findComment-837886 Share on other sites More sharing options...
eggerda Posted May 20, 2009 Author Share Posted May 20, 2009 Thanks guys! Dan Link to comment https://forums.phpfreaks.com/topic/158859-simple-php-string-operation/#findComment-837903 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.