CodesJava

Easy learning with example program codes

PHP String Functions


String Functions are the built-in functions provided by PHP to operate and manipulate a string. PHP provides a number of string functions. Some of the MOST USED string functions are listed below:

 

SYNTAX USES
string strtolower ( string $string ) It converts a string to lowercase letters
string strtoupper ( string $string ) It converts a string to uppercase letters
string ucfirst ( string $str ) It converts the first character of a string to uppercase
string lcfirst ( string $str ) It converts the first character of a string to lowercase
string ucwords ( string $str ) It converts the first character of each word in a string to uppercase
string strrev ( string $string ) It reverses a string
int strlen ( string $string ) It returns the length of a string

 

Example:

<!DOCTYPE html>
<html>
<body>
 
<?php  
$str="Hello World";  
$str=strtolower($str);  
echo "$str <br>";  
$str=strtoupper($str);  
echo "$str <br>";
$str=lcfirst($str);  
echo "$str <br>";  
$str=strrev($str);  
echo "$str <br>";
$str=strlen($str);  
echo "$str <br>";
 
$str="hello World";
$str=ucfirst($str);
echo "$str <br>";
 
$str="hello world";  
$str=ucwords($str);  
echo "$str <br>";
?> 
 
</body>
</html>

Output

hello world
HELLO WORLD
hELLO WORLD
DLROW OLLEh
11
Hello World
Hello World
Posted in PHP   
Sign Up/ Sign In
Ask a Question


Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki