Tag: web technology

Questions Related to web technology

The following piece of script will output: $email='[email protected]'; $new=strstr($email, '@'); print $new; ?>

  1. admin

  2. admin@psexam

  3. @psexam.com

  4. psexam.com


Correct Option: C
Explanation:

To solve this question, the user needs to know the basic syntax of the PHP programming language and the function of strstr().

strstr() function is used to find the first occurrence of a string inside another string. It returns a part of the haystack string starting from the first occurrence of the needle string to the end of the haystack string.

In the given script, the variable $email is assigned the string value of '[email protected]'. The strstr() function is called with two arguments: the $email variable and '@'. The function returns the first occurrence of '@' in the $email variable and assigns it to the variable $new. The print statement then outputs the value of $new.

Now, let's go through each option and explain why it is right or wrong:

A. admin: This option is incorrect because the strstr() function returns everything from the first occurrence of '@' to the end of the string. Therefore, the value of $new is '@psexam.com', not 'admin'.

B. admin@psexam: This option is incorrect because the strstr() function includes the needle string in the returned value. Therefore, the value of $new is '@psexam.com', not 'admin@psexam'.

C. @psexam.com: This option is correct. The strstr() function returns the first occurrence of '@' in the $email variable, which is '@psexam.com'. Therefore, the value of $new is '@psexam.com'.

D. psexam.com: This option is incorrect because the strstr() function returns the string starting from the first occurrence of '@'. Therefore, the returned value includes the '@' symbol. The value of $new is '@psexam.com', not 'psexam.com'.

The Answer is: C

  1. Faster

  2. Slower

  3. The execution speed is similar

  4. All of above


Correct Option: B

The most portable version of PHP tag that is compatible to embed in XML or XHTML too is:

  1. ?>


Correct Option: D
Explanation:

To solve this question, the user needs to know about the different PHP tags and their compatibility with XML or XHTML.

Option A: ?> is a valid PHP tag but it is not recommended to use as it may conflict with XML processing instruction. It is also not recommended to use with XHTML.

Option B: is not a valid PHP tag and will not be parsed as PHP code. It may work on some servers with specific configurations, but it is not portable or recommended.

Option C: is a valid PHP tag, but it is not compatible with XML or XHTML. It is used in ASP-style syntax.

Option D: is the recommended and most portable version of the PHP tag. It is compatible with XML or XHTML and is widely supported on different servers and configurations.

Therefore, the correct answer is:

The Answer is: D.

  1. somerar is 15

  2. somerar is 16

  3. somerar is 1

  4. error in code


Correct Option: B
Explanation:

To solve this question, the user needs to understand the concept of global variables and function in PHP. The script defines a global variable named $somevar with a value of 15, and a function named addit() that increments the value of $somevar by one and then outputs its new value. The function explicitly states the variable is global using the global keyword.

When the addit() function is called, it will first increment the value of $somevar by one, resulting in a value of 16. Then, the function will output the string "somerar is 16" using the echo statement.

Therefore, the correct answer is:

The Answer is: B. somerar is 16

Which of the following delimiting method is known as string Interpolation?

  1. delimited by single quote

  2. delimited by double quote

  3. delimited by <<< identifier

  4. All of above


Correct Option: C

AI Explanation

To answer this question, you need to understand different delimiting methods used for string interpolation.

Option A) Delimited by single quote - This option is incorrect because string interpolation is not typically done using single quotes. Single quotes are commonly used to delimit string literals in programming languages, but they do not support string interpolation.

Option B) Delimited by double quote - This option is incorrect because while double quotes can be used to delimit string literals and support some form of string interpolation in some programming languages, it is not the specific delimiting method known as string interpolation.

Option C) Delimited by <<< identifier - This option is correct because the <<< identifier (also known as heredoc syntax) is a specific delimiting method used for string interpolation in some programming languages. It allows multiline strings with variable interpolation.

Option D) All of the above - This option is incorrect because not all of the above options are correct. Only option C is the correct delimiting method known as string interpolation.

Therefore, the correct answer is C) delimited by <<< identifier. This option is correct because it represents the specific delimiting method known as string interpolation.

  1. Local variables

  2. Function parameters

  3. Hidden variables

  4. Global variables


Correct Option: C