w3reference home
PHP Tutorial


Bookmark and Share

String Capitalization

String capitalization is used to change the case of a string. There are three functions for this purpose namely, strtoupper, strtolower and ucwords. Let's have a look at each of these examples separately.

strtoupper()

This function converts the entire specified string to upper case. Let's see this with an example:
<?php
$str="We capitalize this string!";
$str_upper=strtoupper($str);
echo $str_upper;
?>
The output of the above PHP code will be:
WE CAPITALIZE THIS STRING!
By using this function, all the alphabets will be capitalized and the numbers and special characters will remain as they are.

strtolower()

This function converts the entire specified string to lower case. It's functioning is similar to that of "strtoupper()" function. Let's see this example:
<?php
$str="PHP is a good language!";
$str_lower=strtolower($str);
echo $str_lower;
?>
The output of the above PHP script will be:
php is a good language!

ucwords()

This function capitalizes starting letter of each word in the string specified. This function comes in handy when writing a title or a heading. Let's see this example that will demonstrate the function, ucwords():
<?php
$str="This title will look good!";
$str_uc=ucwords($str);
echo $str_uc;
?>
The output will be:
This Title Will Look Good!
This function ensures that the starting letters of each word in the string are capitalized. The rest of the string remains as it is. If there is a letter in upper case in the middle of the word, it will remain in upper case.
Code Validator
Learn FTP
Color finder
Link Checker
Free web designs
Coming soon!
Interview Questions...
'w3reference : Learn by examples ... Advanced to beginner's tutorials ...'
Ajax: AJAX tutorial1 | Apache: Apache HTTP Server | Restarting Apache | CSS: CSS Border | CSS Syntax | CSS Selector | CSS Comment | CVS: CVS Release | CVS Login | CVS Logout | CVS Annotate | Databases: Rolap Tutorial | OLAP Tutorial | OLTP Tutorial | data warehousing | Expect: HTML: html | Linux: Dot (.) conf files | Linux Mount Point | Linux Filesystem | SSH Tutorial | Linux Commands: cal | cat | cfdisk | chroot | MySQL: MySQL Commands | PHP: PHP Basics | PHP Variables | PHP Output (echo/print) | PHP String Concat | PL/SQL: PL/SQL Data Types | PL/SQL Control Structures | PL/SQL File Extensions | PL/SQL DBMS_OUTPUT package | Python: My first Python program | Shell: Starting Bash | Bash Redirection | Bash Pipes | Bash Variables | SQL: SQL Transactions | SQL Constraints | SQL Drop | SQL Union & Union All | SVN: svn architecture | SVN Repository | SVN Import | SVN Checkout | Tech: soap | Web Designing: Web Hosting | HTML/XHTML/CSS code validator | Learn FTP | Search Engine Optimization Tips | www: XML: XML vs HTML | XML Syntax | XML Tags, Elements and Attributes | XML Namespaces |
Sitemap | Disclaim | Privacy Policy | Contact | ©2007-2009 w3reference.com All Rights Reserved.