Aim:
PHP script to a) Find the length of a string. b) Count no of words in a string. c) Reverse a string. d) Search for a specific string.
Source Code:
Week-2/Week2.php
<html>
<head>
<title>String Operations in PHP</title>
</head>
<body>
<?php
/*
strlen() function returns the length of a string.
str_word_count() function counts the number of words in a string.
strrev() function reverses a string.
strpos() function searches for a specific text within a string.
*/
$mystr="PHP is a server side scripting language";
echo "<strong>The given string is : </strong> $mystr<br>";
echo "<strong>The length of given string is : </strong> ".strlen($mystr)."<br>";
echo "<strong>The number of words are : </strong>".str_word_count($mystr)."<br>";
echo "<strong>The Reverse of a given String is : </strong> ".strrev($mystr)."<br>";
$substr="server";
echo "<strong>The Position of a Sub String '$substr' in the String is : </strong> ".strpos($mystr,$substr);
?>
</body>
</html>
<html>
<head>
<title>String Operations in PHP</title>
</head>
<body>
<?php
/*
strlen() function returns the length of a string.
str_word_count() function counts the number of words in a string.
strrev() function reverses a string.
strpos() function searches for a specific text within a string.
*/
$mystr="PHP is a server side scripting language";
echo "<strong>The given string is : </strong> $mystr<br>";
echo "<strong>The length of given string is : </strong> ".strlen($mystr)."<br>";
echo "<strong>The number of words are : </strong>".str_word_count($mystr)."<br>";
echo "<strong>The Reverse of a given String is : </strong> ".strrev($mystr)."<br>";
$substr="server";
echo "<strong>The Position of a Sub String '$substr' in the String is : </strong> ".strpos($mystr,$substr);
?>
</body>
</html>
No comments