What will be the output of the following PHP code?
<?php
$username = "jasoN";
if (ereg("([^a-z])",$username))
echo "Username must be all lowercase!";
else
echo "Username is all lowercase!";
?>
<?php
$username = "jasoN";
if (ereg("([^a-z])",$username))
echo "Username must be all lowercase!";
else
echo "Username is all lowercase!";
?>
A. Error
B. Username must be all lowercase!
C. Username is all lowercase!
D. No Output is returned
Answer: Option B
Solution(By Examveda Team)
Because the provided username is not all lowercase, ereg() will not return FALSE (instead returning the length of the matched string, which PHP will treat as TRUE), causing the message to output.Related Questions on Regular Expressions
A. 1 and 2
B. 2 and 4
C. 1 and 4
D. 2 and 3
Join The Discussion