PHP Strings
Here we play with strings.$myName="My Name is Rocky.";
$myLoc=" I live in jungle";
To concatenate two variables together, use the dot (.) or (,) operator:
<?php
$myName="My Name is Rocky.";
$myLoc="I live in jungle";
echo $myName,' ',$myLoc;
?>
$myName="My Name is Rocky.";
$myLoc="I live in jungle";
echo $myName,' ',$myLoc;
?>
My Name is Rocky. I live in jungle
Note: (,) operator is fast to (.) operator.
Some String functions
strlen() Count the length of String
<?php
$s1 = 'Rocky Don';
echo strlen($s1);
echo "<br />";
$s2 = 'a b c d e';
echo strlen($s2);
?>
$s1 = 'Rocky Don';
echo strlen($s1);
echo "<br />";
$s2 = 'a b c d e';
echo strlen($s2);
?>
9
9
strcmp() It Compare two strings. Comparison is case sensitive.9
If $str1 == $str2 strcmp return 0.
If $str1 > $str2 strcmp return 1.
If $str1 < $str2 strcmp return -1.
<?php
$str1="ram";
$str2="Ram";
$result;
$result=strcmp($str1,$str2);
echo $result;
?>
$str1="ram";
$str2="Ram";
$result;
$result=strcmp($str1,$str2);
echo $result;
?>
1
strrev Reverse a string.
<?php
$str="Hello";
echo strrev($str);
?>
$str="Hello";
echo strrev($str);
?>
olleH
Next: Operators