PHP String

PHP String  : -


A set of character is called string. PHP String Provide us various prefdefind function which access and manipulate php string

strlen() function return length of string


<?php 
$string = "hello phpcooker";
echo strlen($string); //output 15

?>

strtoupper() function convert string to upper case


<?php 
$string = "hello phpcooker";
echo strtoupper($string); //output HELLO PHPCOOKER

?>

strtolower() function convert string to lower case


<?php 
$string = "HELLO";
echo strtolower($string); //output hello

?>

ucfirst() function convert first character of string to upper case


<?php 
$string = "hello";
echo ucfirst($string); // output Hello

?>

lcfirst() function convert first character of string to lower case


<?php 
$string = "Hello";
echo lcfirst($string); //output hello
?>

substr() function return part of string 


<?php 
$string = "hello phpcooker";
echo substr($string,6,3); //output php becouse sbstr count from 0 index
?>

str_replace() replace character 


<?php 
$string = "hello phpcooker";
echo str_replace('phpcooker','php',$string); //output hello php

?>
Previous Tutorial

PHP variables