Develop a new think

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;
?>
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);
?>
9
9
strcmp() It Compare two strings. Comparison is case sensitive.
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;
?>
1
strrev Reverse a string.
<?php
$str="Hello";
echo strrev($str);
?>
olleH

Next: Operators

All links Introduction | Installation | Syntax | Variables | Strings | Operators | Comments
web counter