SQL PHP HTML ASP JavaScript articles and free scripts to download
PHP String Functions

Converting the first letter to upper case of every word

We can use php string function ucwords to change all first character of words present in a string to upper case or capitalize the first letter of each word.

Here is the syntax

$output=ucwords($input_str);

You can see the output string is $output and input string is $input_str in the above example.
Now let us try with one example

Here is a string variable $str with some string inside it. We will use ucwords to capitalize first chars of every words inside it.

$str="welcome to plus2net.com. you can learn web programming here";
$str=ucwords($str);
echo $str;

The output is here

Welcome To Plus2net.com. You Can Learn Web Programming Here

Changing first character of first word only to uppercase.

Instead of changing first char of all the words to upper case we can change to upper case for the first char of (only ) first word of total sting by using ucfirst() function.

$ar="welcome to plus2net php section";
echo ucfirst($ar);

The output is here

Welcome to plus2net php section

how to change all the letters to upper case

Be the first to post comment on this article :


Google+
PHP String Functions
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy



HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2015 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer