Tag: web technology

Questions Related to web technology

When you need to obtain the ASCII value of a character which of the following function you apply in PHP?

  1. chr( );

  2. asc( );

  3. ord( );

  4. val( );


Correct Option: C

AI Explanation

To obtain the ASCII value of a character in PHP, you would use the ord() function.

Let's go through each option to understand why it is correct or incorrect:

Option A) chr() - This option is incorrect because the chr() function is used to convert an ASCII value to its corresponding character.

Option B) asc() - This option is incorrect because there is no built-in asc() function in PHP. It is not a valid function for obtaining the ASCII value of a character.

Option C) ord() - This option is correct because the ord() function in PHP is used to obtain the ASCII value of a character.

Option D) val() - This option is incorrect because the val() function in PHP is used to obtain the numerical value of a variable, not the ASCII value of a character.

The correct answer is option C) ord(). This option is correct because the ord() function is specifically designed to obtain the ASCII value of a character in PHP.

  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
  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

  1. delimited by single quote

  2. delimited by double quote

  3. delimited by <<< identifier

  4. All of above


Correct Option: C
  1. Local variables

  2. Function parameters

  3. Hidden variables

  4. Global variables


Correct Option: C