PHP STRING FUNCTION with example

PHP STRING FUNCTIONS

PHP support a large number of built in string functions.here we consider the basic function for

inspecting

modifying

printing string

SL NO NAME description example
1

Strlen()

To get string length


return the length of the string on succes,and 0 if the string is empty

$str = 'abcdef';
echo strlen($str);

the output will be 6
2

Strops()

FIND position of first occurense of a string


item to be searched . if item is not a string .
it is a converted to and integer and appliedd as the ordinal value of a character


$mystring ='abc';
$findme = 'a';
$pos = $strpos($mystring,$findme);

the output will 0
3

strrpos()

Find the posistion of the last occurense of a substring in a string


Return the numeric position of the last occurense of data in the string ,
return false if the item was not found
$mystring ='abcda';
$findme = 'a';
$pos = strrpos($mystring,$findme);
the output will 4
4

Strcmp()

Binery safe string comparing

strcmp ($str1,$str2)
This function return < 0 if str1 is less than str2;>0 if str1 is
greater than str2, and 0 if they are equal note that this comparison is case sensitive
$string1 = "abc";
$string2 = "abcd";
$value = strcmp ($string1,$string2);
if($value < 0)
{
echo "string1 is lesthan $string2";
}
else
{
echo "string1 is greaterthan $string2";

} 
the output will be string1 is lesthan abcd