MOST IMPORTANT QUESTIONS GENERALLY USED TO BE ASKED IN THE INTERVIEW ON STRING FUNCTIONS IN PHP
MOST IMPORTANT QUESTIONS GENERALLY USED TO BE ASKED IN THE INTERVIEW ON STRING FUNCTIONS IN PHP
Q1. What is string() function?
Ans: string() function is the manipulation of string.
Q2. What is meant by ucfirst() function? Explain with an example.
Ans: ucfirst() function is the upper case of the first word in a string.
CODE =>
<?php
$str="i am going to school";
$ucfirst=ucfirst($str);
echo "$ucfirst";
?>
OUTPUT =>
I am going to school
Q3. What is meant by lcfirst() function? Explain with an example.
Ans: lcfirst() function is the lowercase of the first word in a string.
CODE =>
<?php
$str="Welcome to our school";
$lcfirst=lcfirst($str);
echo "$lcfirst";
?>
OUTPUT =>
welcome to our school
Q4. What is meant by ucwords() function? Explain with an example.
Ans: ucwords() function is to provide uppercase to all words in a string.
CODE =>
<?php
$str="hello welcome to our cricket academy";
$ucwords=ucwords($str);
echo "$ucwords";
?>
OUTPUT =>
Hello Welcome To Our Cricket Academy
Q5. What is meant by strlen() function? Explain with an example.
Ans: strlen() function is to count the length of a string.
CODE =>
<?php
$str="Welcome to PWC";
$strlen=strlen($str);
echo "$strlen";
?>
OUTPUT =>
14
Q6. What is meant by str_word_count() function? Explain with an example.
Ans: str_word_count() function is to count the length of words in a string.
CODE =>
<?php
$str="Hello welcome to ejobindia";
$strwrdcnt=str_word_count($str);
echo "$strwrdcnt";
?>
OUTPUT =>
4
Q7. What is meant by str_replace() function? Explain with an example.
Ans: str_replace() function is to replace the characters with some other characters in a string.
CODE =>
<?php
$str="This is our library";
$strrplc=str_replace("This", "It", $str);
echo "$strrplc";
?>
OUTPUT =>
It is our library
Q8. When we use i character or i alphabet?
Ans: We use i character or i alphabet when we do any incase sensitive work.
Q9. What is meant by str_split() function? Explain with an example.
Ans: str_split() function is used to split each alphabet of a string into an array.
CODE =>
<?php
$str="Test Match Between India Vs South Africa Will Be Played In Eden Garden From Today Onwards";
$strsplt=str_split($str);
print_r($strsplt);
?>
OUTPUT =>
Array ( [0] => T [1] => e [2] => s [3] => t [4] => [5] => M [6] => a [7] => t [8] => c [9] => h [10] => [11] => B [12] => e [13] => t [14] => w [15] => e [16] => e [17] => n [18] => [19] => I [20] => n [21] => d [22] => i [23] => a [24] => [25] => V [26] => s [27] => [28] => S [29] => o [30] => u [31] => t [32] => h [33] => [34] => A [35] => f [36] => r [37] => i [38] => c [39] => a [40] => [41] => W [42] => i [43] => l [44] => l [45] => [46] => B [47] => e [48] => [49] => P [50] => l [51] => a [52] => y [53] => e [54] => d [55] => [56] => I [57] => n [58] => [59] => E [60] => d [61] => e [62] => n [63] => [64] => G [65] => a [66] => r [67] => d [68] => e [69] => n [70] => [71] => F [72] => r [73] => o [74] => m [75] => [76] => T [77] => o [78] => d [79] => a [80] => y [81] => [82] => O [83] => n [84] => w [85] => a [86] => r [87] => d [88] => s )
Q10. What is meant by str_repeat() function? Explain with an example.
Ans: str_repeat() function is used to execute the same thing multiple times which we can also called it as multiplication.
CODE =>
<?php
$str="Capgemini";
$strrpt=str_repeat($str, 5);
echo "$strrpt";
?>
OUTPUT =>
CapgeminiCapgeminiCapgeminiCapgeminiCapgemini
Q11. What is meant by strstr() function? Explain with an example.
Ans: strstr() function is the string of a string which is used to create the substring from a string.
CODE =>
<?php
$str="Welcome to Lords";
$strstr=strstr($str, "co");
echo "$strstr";
?>
OUTPUT =>
come to Lords
Q12. What is meant by strpos() function? Explain with an example.
Ans: strpos() function is used to check the position of an alphabet in a string.
CODE =>
<?php
$str="Welcome Team India";
$strpos=strpos($str, "a");
echo "$strpos";
?>
OUTPUT =>
10
Q13. What is meant by strrev() function? Explain with an example.
Ans: strrev() function is used to reverse the entire string.
CODE =>
<?php
$str="I am going to office";
$strrev=strrev($str);
echo "$strrev";
?>
OUTPUT =>
eciffo ot gniog ma I
Q14. What is meant by strrpos() function? Explain with an example.
Ans: strrpos() function is used to count the position of a string from the reverse.
CODE =>
<?php
$str="TCS is an MNC Company";
$strrpos=strrpos($str, "M");
echo "$strrpos";
?>
OUTPUT =>
10
Q15. What is meant by md5() function? Explain with an example.
Ans: md5() function is known as message digest algorithm 5. It's function is used to encrypt it's file into 32 bytes.
CODE =>
<?php
$str="Ayan";
$md5=md5($str);
echo "$md5";
?>
OUTPUT =>
6574bba3da4155c410113ab1e67e505d
Comments
Post a Comment