PHP PR5 (22203C0007)
PHP PR5 (22203C0007)
Code
<?php
$str = "Hello World of PHP";
echo "Original string: ".$str."\n";
echo "Word Count \n";
echo str_word_count($str)."\n";
echo "String Lenght \n";
echo strlen($str)."\n";
echo "String Repeat \n";
echo str_repeat($str,2)."\n";
echo "String Replace \n";
echo str_replace("World","PHP",$str)."\n";
echo "String Replace \n";
echo str_replace("PHP","World",$str)."\n";
echo "String Compare Hello and Hello\n";
echo strcmp("Hello","Hello")."\n";
echo "String Compare Hello and hello\n";
echo strcmp("Hello","hello")."\n";
echo "String split \n";
$s = str_split($str);
print_r($s)."\n";
echo "String Reverse \n";
echo strrev($str)."\n";
echo "String Lowercase \n";
echo strtolower($str)."\n";
echo "String Uppercase \n";
echo strtoupper($str)."\n";
echo "String Ucwords \n";
echo ucwords($str)."\n";
echo "String position of World\n";
echo strpos($str,"World")."\n";
echo "String Shuffle \n";
echo str_shuffle($str)."\n";
echo "String Trim \n";
echo trim($str)."\n";
echo "String Rtrim \n";
echo rtrim($str)."\n";
echo "String Ltrim \n";
echo ltrim($str)."\n";
echo "String Chop \n";
echo chop($str,"PHP")."\n";
echo "String Chunk Split \n";
echo chunk_split($str,5)."\n";
?>
Output
Q2 Find the length of a string without using string functions
Code
<?php
$input = "Student";
$count = 0;
while (isset($input[$count])) {
$count++;
}
Code
<?php
$str = "student id";
$arr = explode(" ",$str);
$coun = count($arr);
echo "No of words in ".$str." is ".$coun."\n";
?>
Output
Grade and Process Related Product Related Dated Sign
Dated (15) (10)
Signature
of Teacher