Novartis Previous Years Solved Sample Placement Papers
-
How many functions does PHP offer for searching and modifying strings using Perl-compatible regular expressions?
A. 10
B. 7
C. 8
D. 9 Answer: Option C
- Solution: The functions are preg_filter(), preg_grep(), preg_match(), preg_match_all(), preg_quote(), preg_replace(), preg_replace_callback(), and preg_split().
-
Which of the following web servers are required to run the PHP script?
A. Apache and PHP
B. IIS
C. XAMPP
D. Any of the mentioned Answer: Option B
- Solution: PHP requires a web server to run scripts. IIS, XAMPP, and Apache are suitable, but IIS is highlighted here.
-
What will be the output of the following PHP code snippet?
<?php
$url = "[email protected]";
echo ltrim(strstr($url, "@"),"@");
?>
C. phpmcq@
D. sanfoundry.com Answer: Option D
- Solution: The strstr() function returns the portion of the string starting from the first occurrence of "@", and ltrim() removes the "@".
-
Which of the following PHP functions can be used to get the current memory usage?
A. memory_get_usage()
B. memory_get_peak_usage()
C. get_peak_usage()
D. get_usage() Answer: Option A
- Solution: The memory_get_usage() function returns the memory currently allocated to the script. The 'real_usage' parameter can specify whether to include unused pages.
-
Which one of the following PHP functions is used to determine a file’s last access time?
A. filetime()
B. fileatime()
C. fileltime()
D. filectime() Answer: Option B
- Solution: The fileatime() function returns the last access time of a file in Unix timestamp format or FALSE on error.
-
What will be the output of the following PHP code?
<?php
$x = 5;
$y = 10;
function fun() {
$y = $GLOBALS['x'] + $GLOBALS['y'];
}
fun();
echo $y;
?>
A. 5
B. 10
C. 15
D. Error Answer: Option B
- Solution: The $GLOBALS array is used to access global variables, but the global $y is not updated in the function, so it remains 10.
-
PHP recognizes constructors by the name _________
A. function __construct()
B. function _construct()
C. classname()
D. _construct() Answer: Option A
- Solution: PHP uses the double underscore followed by the "construct" keyword to define constructors. The correct syntax is function __construct().