Bird
0
0

Which PHP function is used to validate if a string is a valid URL?

easy📝 Conceptual Q2 of 15
PHP - Superglobals and Web Context
Which PHP function is used to validate if a string is a valid URL?
Afilter_var() with FILTER_VALIDATE_URL
Bhtmlspecialchars()
Ctrim()
Dstr_replace()
Step-by-Step Solution
Solution:
  1. Step 1: Identify URL validation function

    PHP's filter_var() with FILTER_VALIDATE_URL checks if a string is a valid URL format.
  2. Step 2: Review other functions

    htmlspecialchars() escapes HTML, trim() removes spaces, str_replace() replaces strings; none validate URLs.
  3. Final Answer:

    filter_var() with FILTER_VALIDATE_URL -> Option A
  4. Quick Check:

    URL validation = filter_var + FILTER_VALIDATE_URL [OK]
Quick Trick: Use filter_var() with FILTER_VALIDATE_URL for URLs [OK]
Common Mistakes:
  • Using htmlspecialchars() for validation
  • Confusing trim() with validation
  • Trying to validate URLs with str_replace()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes