1.
pHP is a widely used ……………. scripting language that is especially suited for web development and can be embedded into HTML.
Correct Answer
A. Open source general purpose
Explanation
PHP is a widely used scripting language that is especially suited for web development and can be embedded into HTML. It is open source, meaning that it is freely available for anyone to use and modify. It is also a general-purpose language, which means that it can be used for a wide range of applications, not just web development.
2.
Which of the following variables is not a predefined variable?
Correct Answer
B. $ask
Explanation
The variable "$ask" is not a predefined variable. In PHP, predefined variables are variables that are already defined and can be used without any additional declaration. Variables like "$get", "$request", and "$post" are examples of predefined variables in PHP, which are used to retrieve data from the URL, server, and HTTP POST requests respectively. However, "$ask" is not a predefined variable in PHP.
3.
Given a variable $email containing the string [email protected] which of the following will extract the string example.com?
Correct Answer
D. Substr($email, strops(($email,”@”)+1);
Explanation
The correct answer is substr($email, strops(($email,"@")+1). This is because the function strops($email,"@") will return the position of the "@" symbol in the string $email. Adding 1 to this position will give us the starting position of the substring we want to extract. Then, the substr() function will extract the substring starting from that position until the end of the string, giving us "example.com".
4.
Which of the following will not combine strings $s1 and $s2 into a single string?
Correct Answer
A. $s1+$s2
Explanation
The correct answer is $s1+$s2. This is because the "+" operator in PHP is used for numerical addition, not for string concatenation. In order to combine two strings in PHP, the "." operator should be used. The other options, "{$s1}{$s2}" and implode(' ', array($s1,$s2)), are valid ways to combine strings in PHP.
5.
The ____ function can be used to compare two strings using a case-insensitive binary algorithm.
Correct Answer
C. Strcasecmp()
Explanation
The strcasecmp() function can be used to compare two strings using a case-insensitive binary algorithm. This means that the function will compare the strings without considering the difference between uppercase and lowercase letters. This is useful when you want to compare strings without being sensitive to the case of the letters.
6.
A variable $word is set to “HELLO WORLD”, which of the following script returns in title case?
Correct Answer
B. Echo ucwords(strtolower($word))
Explanation
The function ucwords() capitalizes the first letter of each word in a string. In this case, the string "HELLO WORLD" is first converted to lowercase using strtolower(), and then ucwords() is applied to capitalize the first letter of each word, resulting in "Hello World". The other options either capitalize only the first letter of the entire string (ucfirst($word)), or do not convert the string to title case at all.
7.
The difference between include() and require()
Correct Answer
A. Are different how they handle failure
Explanation
The correct answer is that include() and require() are different in how they handle failure. Include() produces a Fatal Error, which means that if the included file is not found or there is an error in the file, the script will stop executing. On the other hand, require() results in a Warning, which means that if the required file is not found or there is an error, the script will continue executing but with a warning message.
8.
Trace the odd data type.
Correct Answer
B. Integer
Explanation
The odd data type in this list is "integer" because it is the only data type that represents whole numbers without any decimal places. The other data types, such as "floats," "doubles," and "real number," all allow for decimal places in their values.
9.
Which of the following are valid float values?
Correct Answer
D. All of above
Explanation
All of the given values are valid float values. 4.5678 and 4.0 are decimal numbers, which can be represented as floats. 7e4 is a scientific notation for 7 multiplied by 10 to the power of 4, which is also a valid float value. Therefore, all of the given values are valid float values.
10.
In pHP string data are
Correct Answer
C. Delimited by
Explanation
In PHP, string data can be delimited by single quotes (''), double quotes ("") or even by using the heredoc syntax. Therefore, the correct answer is "delimited by all of the above".
11.
Casting operator introduced in pHP 6 is
Correct Answer
B. (int64)
Explanation
The casting operator (int64) is used in PHP 6 to convert a value to a 64-bit integer. This operator is used when you want to specifically convert a value to a 64-bit integer data type.
12.
When defining identifier in pHP you should remember that
Correct Answer
C. Both of above
Explanation
When defining an identifier in PHP, it is important to remember that identifiers are case sensitive. This means that $result is considered different than $ result. Additionally, identifiers can be of any length. Therefore, the correct answer is that both of these statements are true.
13.
The output of following script would be
$somerar=15;
function ad it () {
GLOBAL $somevar;
$somerar++ ;
echo "somerar is $somerar";
}
addit ();
Correct Answer
B. Somerar is 16
Explanation
The output of the script would be "somerar is 16". This is because the script defines a global variable $somerar with a value of 15. Then, a function called addit() is defined, which increments the value of $somerar by 1 and echoes the result. Finally, the addit() function is called, resulting in the value of $somerar being incremented to 16 and echoed.
14.
Which of the following method sends input to a script via a URL?
Correct Answer
A. Get
Explanation
The correct answer is "Get". The Get method is used to send input to a script via a URL. It appends the input data to the URL as query parameters, allowing the data to be visible in the URL itself. This method is commonly used for retrieving data from a server or fetching web pages.
15.
Which of the following method is suitable when you need to send larger form submissions?
Correct Answer
B. Post
Explanation
The Post method is suitable when you need to send larger form submissions. Unlike the Get method, which appends form data to the URL, the Post method sends the data in the body of the HTTP request. This allows for larger amounts of data to be sent securely and efficiently. Therefore, the Post method is the recommended choice for sending larger form submissions.
16.
The function setcookie( ) is used to
Correct Answer
C. Store data in cookie variable
Explanation
The function setcookie() is used to store data in a cookie variable. It allows the programmer to set a cookie with a specified name, value, expiration time, path, and domain. This function enables the server to send a cookie to the client's browser, which can then be stored and later sent back to the server with subsequent requests. This allows the server to remember information about the user, such as their preferences or login status. Therefore, the correct answer is "Store data in cookie variable".
17.
To work with remote files in pHP you need to enable.
Correct Answer
A. Allow_url_fopen
Explanation
To work with remote files in PHP, you need to enable the "allow_url_fopen" option. This option allows PHP to open and read files from remote locations using URLs. By enabling this option, you can use functions like file_get_contents() or fopen() to access and manipulate remote files. The "allow_remote_files" option is not a valid option in PHP, so the correct answer is "allow_url_fopen".
18.
Which of the following function returns the number of characters in a string variable?
Correct Answer
D. Strlen($variable)
Explanation
The function strlen($variable) is used to return the number of characters in a string variable. It calculates and returns the length of the string, which represents the number of characters in the string. This function is commonly used in programming to determine the length of a string and perform operations based on that length.
19.
The left associative dot operator (.) is used in pHP for
Correct Answer
B. Concatenation
Explanation
The left associative dot operator (.) is used in PHP for concatenation. It is used to combine two strings together to create a new string. This operator allows you to join multiple strings or string variables into a single string. For example, if you have two variables $str1 = "Hello" and $str2 = "World", using the dot operator like $str1 . $str2 will result in the string "HelloWorld".
20.
Which of the following variable assignments is 'by value' assignment in pHP.
Correct Answer
A. $value1= $value?
Explanation
The correct answer is $value1= $value. In PHP, a 'by value' assignment means that the value of the variable is copied to another variable. In this case, the value of $value is being assigned to $value1, creating a new variable with the same value. The other options involve passing the variable by reference, indicated by the use of the ampersand (&) symbol, which means that both variables will refer to the same memory location.
21.
Which of the following functions require the allow-url-fopen must be enabled?
Correct Answer
C. Both of above
Explanation
The functions include() and require() both require the allow-url-fopen to be enabled. These functions are used to include files in PHP scripts. When allow-url-fopen is enabled, these functions can include files from remote URLs as well. If allow-url-fopen is disabled, including files from remote URLs will not be possible. Therefore, both of these functions require the allow-url-fopen to be enabled.