ExamVeda
Login
Home
11
How many functions does PHP offer for searching and modifying strings using Perl-compatible regular expressions.
Discuss
Answer & Solution
Answer: Option B
Solution:
The functions are preg_filter(), preg_grep(), preg_match(), preg_match_all(), preg_quote(), preg_replace(), preg_replace_callback(), and preg_split().
12
What will be the output of the following PHP code?
<?php
$foods = array("pasta", "steak", "fish", "potatoes");
$food = preg_grep("/^s/", $foods);
print_r($food);
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
This function is used to search an array for foods beginning with s.
13
Say we have two compare two strings which of the following function/functions can you use?
1. strcmp()
2. strcasecmp()
3. strspn()
4. strcspn()
Discuss
Answer & Solution
Answer: Option D
Solution:
All of the functions mentioned above can be used to compare strings in some or the other way.
14
Which one of the following functions will convert a string to all uppercase?
Discuss
Answer & Solution
Answer: Option A
Solution:
Its prototype follows string strtoupper(string str).
15
What will be the output of the following PHP code?
<?php
$title = "O'malley wins the heavyweight championship!";
echo ucwords($title);
?>
Discuss
Answer & Solution
Answer: Option B
Solution:
The ucwords() function capitalizes the first letter of each word in a string. Its prototype follows: string ucwords(string str).
16
What will be the output of the following PHP code?
<?php
echo str_pad("Salad", 5)." is good.";
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The str_pad() function pads a string with a specified number of characters.
17
Which one of the following functions can be used to concatenate array elements to form a single delimited string?
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
18
Which one of the following functions finds the last occurrence of a string, returning its numerical position?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
19
What will be the output of the following PHP code?
<?php
$author = "nachiketh@example.com";
$author = str_replace("a","@",$author);
echo "Contact the author of this article at $author.";
?>
Discuss
Answer & Solution
Answer: Option C
Solution:
The str_replace() function case sensitively replaces all instances of a string with another.
20
What will be the output of the following PHP code?
<?php
$url = "contact@examveda.com";
echo ltrim(strstr($url, "@"),"@");
?>
Discuss
Answer & Solution
Answer: Option D
Solution:
The strstr() function returns the remainder of a string beginning with the first occurrence of a predefined string.