Learn PHP MCQs

Prepare PHP MCQs (Multiple choice Questions) for exam and job interviews.

Which of the following functions can be used to find files that match a pattern in PHP?

1) glob()

2) find()

3) pattern_match()

4) search()

Answer : Option 1

What does the `htmlspecialchars()` function do in PHP?

1) Converts special characters to HTML entities

2) Escapes HTML tags

3) Encodes a string into HTML

4) None of the above

Answer : Option 1

How can you protect against SQL injection in PHP?

1) Using prepared statements

2) Escaping input data

3) Using stored procedures

4) All of the above

Answer : Option 4

Which of the following functions is used to remove HTML tags from a string in PHP?

1) strip_tags()

2) remove_tags()

3) clean_html()

4) purify()

Answer : Option 1

How do you create a constant in PHP?

1) define()

2) const

3) set()

4) constant()

Answer : Option 1

Which function is used to get the current timestamp in PHP?

1) time()

2) timestamp()

3) now()

4) current_time()

Answer : Option 1

How do you access a session variable in PHP?

1) $_SESSION

2) $_COOKIE

3) $_VAR

4) $_GLOBALS

Answer : Option 1

What does the `array_key_exists()` function do in PHP?

1) Checks if a key exists in an array

2) Returns the value of a key in an array

3) Deletes a key from an array

4) None of the above

Answer : Option 1

Which of the following functions can be used to compare two strings in PHP?

1) strcmp()

2) compare()

3) strcompare()

4) equal()

Answer : Option 1

How do you convert an array into JSON format in PHP?

1) json_encode()

2) json_decode()

3) array_to_json()

4) convert_to_json()

Answer : Option 1