Bird
0
0

Identify the error in the following PHP code that tries to print the length of a string:

medium📝 Debug Q14 of 15
PHP - String Functions
Identify the error in the following PHP code that tries to print the length of a string:
$text = "PHP Rocks!";
echo strlen $text;
AMissing semicolon after echo
Bstrlen() function call missing parentheses
CVariable name is incorrect
DString is not enclosed in quotes
Step-by-Step Solution
Solution:
  1. Step 1: Check function call syntax

    In PHP, functions require parentheses around their arguments. Here, strlen is called without parentheses.
  2. Step 2: Verify other parts of the code

    The variable name and string are correct, and semicolon is present after echo statement.
  3. Final Answer:

    strlen() function call missing parentheses -> Option B
  4. Quick Check:

    Always use parentheses when calling functions [OK]
Quick Trick: Functions need parentheses even with one argument [OK]
Common Mistakes:
  • Omitting parentheses in function calls
  • Confusing variable names
  • Missing semicolon after statements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes