Web Development Using PHP (4341604)
Web Development Using PHP (4341604)
PRACTICAL 5:
1.Length
<html>
<body>
<?php
echo"Length is ";
echo strlen("Hello world!");
?>
</body>
</html>
Output: Length is 12
2.Word Count
<html>
<body>
<?php
$text = "PHP is an amazing language!";
echo "Word Count: " . str_word_count($text);
?>
</body>
</html>
Output: 5
3.Reverse String
<html>
<body>
<?php
$text = "Hello";
echo "Reversed: " . strrev($text);
?>
</body>
</html>
Output: "olleH"
4.Replace
<html>
<body>
<?php
$text = "I love PHP!";
echo str_replace("PHP", "JavaScript", $text);
?>
</body>
</html>
Output: "I love JavaScript!"
5.Converting Cas
<html>
<body>
<?php
$text = "Hello World!";
echo strtoupper($text);
echo strtolower($text);
?>
</body>
</html>
Output: "HELLO WORLD!"
"hello world!"
5.Removing WhiteSpace
<html>
<body>
<?php
$text = " Hello World! ";
echo trim($text);
?>
</body>
</html>
Output: "Hello World!"
6.Extracting Substring
<html>
<body>
<?php
$text = "Hello World!";
echo substr($text, 6, 5);
?>
</body>
</html>
Output: "World"
—------------------------------------------------------------------------------------------------------------------
8. Each: Returns the current element key-value pair of the given array.
<!DOCTYPE html>
<html>
<body>
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
print_r (each($people));
?>
</body>
</html>
Output: Array ( [1] => Peter [value] => Peter [0] => 0 [key] => 0 )
Output: Array ( [c] => Toyota [b] => BMW [a] => Volvo )