Home » PHP » PHP Uppercase And Lowercase Example

About Olayemi Odunayo

Olayemi Odunayo
I am a programmer and web developer, who has experience in developing websites and writing desktop and mobile applications. I have worked with both schematic and schemaless databases. I am also familiar with third party API and working with cloud servers. I do programming on the client side with Java, JavaScript, html, Ajax and CSS while I use PHP for server side programming.

PHP Uppercase And Lowercase Example

In this example we will show you how to manipulate strings from uppercase to lowercase and from lowercase to uppercase with PHP. This is neccesary when you need to format text.
For this example we will use:

  • A computer with PHP >= 5.5 installed
  • notepad++

Want to be a PHP master?

Subscribe to our newsletter and download the PHP programming Cookbook right now!

In order to get you familiarized with PHP development, we have compiled a comprehensive guide about all major aspects of PHP programming. The perfect tool to boost your WEB development career. Besides reading them online you may download the eBook in PDF format!

 

1. Getting Started

Changing text from uppercase to lowercase or from lowercase to uppercase can become necessary when we are formating or reformatting text. We might need to do this, if for example we want the first letter of the first word in a paragraph to be in uppercase or we want all the words in a paragraph to be in lowercase.

According to library website PHP QR Code is open source (LGPL) library for generating QR Code, 2-dimensional barcode. Based on libqrencode C library, provides API for creating QR Code barcode images (PNG, JPEG thanks to GD2). Implemented purely in PHP.
some of the features of this library are

We want to convert the above text to:

According To Library Website PHP QR Code Is Open Source (LGPL) Library For Generating QR Code, 2-dimensional Barcode. Based On Libqrencode C Library, Provides API For Creating QR Code Barcode Images (PNG, JPEG thanks to GD2). Implemented Purely In PHP.
Some Of The Features Of This Library Are

In the text above we have successfully converted the first letter of each word to uppercase. PHP provides us with so many functions to carry out tasks like this. Lets take a look at some of this functions with some examples.

1.1 strtolower

strtolower converts a string to lowercase. The parameter or arguement supplied to this function is the string we intend to manipulate or convert.

String strtolower(String text);

The function above returns the lowercased string.

index.php

<!DOCTYPE html> 
<html lang=en>
	<head>
	<style>
	</style>

		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi"/>

		<title>
Previewing The QR Code Image

</title>
		
		</head>
	<body>
	<?php
$text="According To Library Website PHP QR Code Is Open Source (LGPL) Library For Generating QR Code, 2-dimensional Barcode. Based On Libqrencode C Library, Provides API For Creating QR Code Barcode Images (PNG, JPEG thanks to GD2). Implemented Purely In PHP.
Some Of The Features Of This Library Are";
// returns  according to library website php qr code is open source (lgpl) library for generating qr code, 2-dimensional barcode. based on libqrencode c library, provides api for creating qr code barcode images (png, jpeg thanks to gd2). implemented purely in php. some of the features of this library are
echo strtolower($text);

?>
	</body>
	</html>

In the example above we converted the whole text to lowercase with the strtolower function.

1.2 strtoupper

strtoupper converts a string to uppercase. The parameter or arguement supplied to this function is the string we intend to manipulate or convert.

String strtoupper(String text);

The function above returns the uppercased string.

index2.php

<!DOCTYPE html> 
<html lang=en>
	<head>
	<style>
	</style>

		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi"/>

		<title>
Previewing The QR Code Image

</title>
		
		</head>
	<body>
	<?php
$text="According To Library Website PHP QR Code Is Open Source (LGPL) Library For Generating QR Code, 2-dimensional Barcode. Based On Libqrencode C Library, Provides API For Creating QR Code Barcode Images (PNG, JPEG thanks to GD2). Implemented Purely In PHP.
Some Of The Features Of This Library Are";
// returns  ACCORDING TO LIBRARY WEBSITE PHP QR CODE IS OPEN SOURCE (LGPL) LIBRARY FOR GENERATING QR CODE, 2-DIMENSIONAL BARCODE. BASED ON LIBQRENCODE C LIBRARY, PROVIDES API FOR CREATING QR CODE BARCODE IMAGES (PNG, JPEG THANKS TO GD2). IMPLEMENTED PURELY IN PHP. SOME OF THE FEATURES OF THIS LIBRARY ARE
echo strtoupper($text);

?>
	</body>
	</html>

In the example above we converted the whole text to uppercase with strtoupper function

1.3 lcfirst

lcfirst converts the first character or letter of a string to lowercase. The parameter or arguement supplied to this function is the string we intend to manipulate or convert.

String lcfirst(String text);

The function above returns the first character of the string as lowercased.

index3.php

<!DOCTYPE html> 
<html lang=en>
	<head>
	<style>
	</style>

		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi"/>

		<title>
Previewing The QR Code Image

</title>
		
		</head>
	<body>
	<?php
$text="According To Library Website PHP QR Code Is Open Source (LGPL) Library For Generating QR Code, 2-dimensional Barcode. Based On Libqrencode C Library, Provides API For Creating QR Code Barcode Images (PNG, JPEG thanks to GD2). Implemented Purely In PHP.
Some Of The Features Of This Library Are";
// returns  according To Library Website PHP QR Code Is Open Source (LGPL) Library For Generating QR Code, 2-dimensional Barcode. Based On Libqrencode C Library, Provides API For Creating QR Code Barcode Images (PNG, JPEG thanks to GD2). Implemented Purely In PHP. Some Of The Features Of This Library Are
echo lcfirst($text);

?>
	</body>
	</html>

1.4 ucfirst

ucfirst converts the first character or letter of a string to uppercase. The parameter or arguement supplied to this function is the string we intend to manipulate or convert.

String ucfirst(String text);

The function above returns the first character of the string as uppercased.

index4.php

<!DOCTYPE html> 
<html lang=en>
	<head>
	<style>
	</style>

		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi"/>

		<title>
Previewing The QR Code Image

</title>
		
		</head>
	<body>
	<?php
$text="according to library website php qr code is open source (lgpl) library for generating qr code, 2-dimensional barcode. based on libqrencode c library, provides api for creating qr code barcode images (png, jpeg thanks to gd2). implemented purely in php. some of the features of this library are ";
//According to library website php qr code is open source (lgpl) library for generating qr code, 2-dimensional barcode. based on libqrencode c library, provides api for creating qr code barcode images (png, jpeg thanks to gd2). implemented purely in php. some of the features of this library are
echo ucfirst($text);

?>
	</body>
	</html>

1.5 ucwords

ucwords converts the first character of each word in a string to uppercase. The parameter or arguement supplied to this function is the string we intend to manipulate or convert.

String ucwords(String text);

The function above returns the first word of the string as uppercased.

index5.php

<!DOCTYPE html> 
<html lang=en>
	<head>
	<style>
	</style>

		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi"/>

		<title>
Previewing The QR Code Image

</title>
		
		</head>
	<body>
	<?php
$text="according to library website php qr code is open source (lgpl) library for generating qr code, 2-dimensional barcode. based on libqrencode c library, provides api for creating qr code barcode images (png, jpeg thanks to gd2). implemented purely in php. some of the features of this library are ";
//According To Library Website Php Qr Code Is Open Source (lgpl) Library For Generating Qr Code, 2-dimensional Barcode. Based On Libqrencode C Library, Provides Api For Creating Qr Code Barcode Images (png, Jpeg Thanks To Gd2). Implemented Purely In Php. Some Of The Features Of This Library Are
echo ucwords($text);

?>
	</body>
	</html>

2. Summary

In this example we learnt how to convert strings from uppercase to lowercase and from lowercase to uppercase. We learnt about PHP ucwords, ucfirst, lcfirst, strtoupper, strtolower function.

3. Download the source code

Download
You can download the full source code of this example here: phpuppercaseandlowercase

Do you want to know how to develop your skillset to become a Web Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. Building web apps with Node.js

2. HTML5 Programming Cookbook

3. CSS Programming Cookbook

4. AngularJS Programming Cookbook

5. jQuery Programming Cookbook

6. Bootstrap Programming Cookbook

 

and many more ....

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Want to take your WEB dev skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • PHP Programming Cookbook
  • jQuery Programming Cookbook
  • Bootstrap Programming Cookbook
  • Building WEB Apps with Node.js
  • CSS Programming Cookbook
  • HTML5 Programming Cookbook
  • AngularJS Programming Cookbook