Q
Which PHP function is used to output content as HTML entities, preventing cross-site scripting (XSS) attacks?

Answer & Solution

Answer: Option A
Solution:
htmlspecialchars() function converts special characters to HTML entities, preventing XSS attacks.
Related Questions on Average

Which function is used to include the contents of another PHP file?

A). include()

B). require()

C). import()

D). load()

What is the file extension for PHP scripts?

A). .html

B). .php

C). .js

D). .css

Which of the following statements is true about PHP variables?

A). Variable names are case-sensitive in PHP

B). PHP variables must start with a dollar sign ($)

C). Variable names cannot contain numbers

D). Variables in PHP cannot be reassigned

How do you output text in PHP?

A). echo 'Hello, World!';

B). console.log('Hello, World!');

C). print('Hello, World!');

D). write('Hello, World!');

Which function is used to retrieve the value of a query string parameter in PHP?

A). $_GET[]

B). $_POST[]

C). $_SESSION[]

D). $_COOKIE[]

What is the purpose of the PHP phpinfo() function?

A). To display information about the PHP environment

B). To execute PHP code

C). To retrieve data from a database

D). To create a new PHP file

Which of the following statements is true about PHP's include and require functions?

A). include will only produce a warning if the file cannot be found, while require will produce an error

B). include will produce an error if the file cannot be found, while require will only produce a warning

C). Both include and require will produce an error if the file cannot be found

D). Both include and require will only produce a warning if the file cannot be found

What is the output of the following code? <?php $a = 10; $b = 5; echo ($a > $b) ? 'Yes' : 'No'; ?>

A). Yes

B). No

C). 1

D). 0

What is the output of the following code? <?php $name = 'Alice'; echo 'Hello, $name!'; ?>

A). Hello, $name!

B). Hello, Alice!

C). Nothing (empty output)

D). Syntax error

Which PHP function is used to check if a file exists in PHP?

A). file_exists()

B). is_file()

C). exists()

D). check_file()