Exp 5
Exp 5
OUTPUT:
2. Write a Program to Count the length of a String, to find the position of String and to
compare two Strings.
CODE:
<html>
<body>
<?php
$str="Hello, Good afternoon";
$str1="Hello";
$str2="hello";
$str3="Evening";
$str4="Evening";
echo "Length of $str= ".strlen($str)."<br>";
echo "Use of strpos():<br>";
echo strpos($str,"good")."<br>";
echo strpos($str,"Good")."<br>";
echo strpos($str,"afternoon",-10)."<br>";
echo "Use of strcmp():<br>";
echo strcmp($str1,$str2)."<br>";
echo strcmp($str2,$str3)."<br>";
echo strcmp($str3,$str4)."<br>";
echo strcmp($str1,$str4)."<br>";
echo "<hr>Midhat Ansari-210403";
?>
</body>
</html>
OUTPUT:
3. Write a Program to Reverse a String.
CODE:
<html>
<body>
<?php
$str="Evening";
echo "Reverse of $str= ".strrev($str)."<br>";
echo "<hr>Midhat Ansari-210403";
?>
</body>
</html>
OUTPUT:
4. Write a Program to Replace a String with the other String. Also count the number of
replacements.
CODE:
<html>
<body>
<?php
$str="Good evening";
echo "Original: ".$str."<br>";
echo str_replace("evening","Morning",$str)."<br>";
$arr=array("blue","red","green","yellow","green");
print_r(str_replace("green","purple",$arr,$r))."<br>";
echo "<br>Replacements: $r"."<br>";
$a=array("blue","red","green","yellow");
$f=array("blue","red","green");
$rep=array("purple","pink");
print_r(str_replace($f,$rep,$a));
echo "<hr>Midhat Ansari-210403";
?>
</body>
</html>
OUTPUT:
5. Write a Program to convert the String to Uppercase, Lowercase, capitalize the first
character of a string.
CODE:
<html>
<body>
<?php
$str="Good evening";
echo "Uppercase of $str= ".strtoupper($str)."<br>";
echo "Lowercase of $str= ".strtolower($str)."<br>";
echo "Use of ucwords()= ".ucwords($str," ")."<br>";
echo "<hr>Midhat Ansari-210403";
?>
</body>
</html>
OUTPUT: