Which PHP function is commonly used to validate an email address?
A
check_email() B
validate_email() C
filter_var() with FILTER_VALIDATE_EMAIL D
preg_match()
Analysis & Theory
`filter_var($email, FILTER_VALIDATE_EMAIL)` checks if the email format is valid.
Which PHP function is used to validate if an input is a valid URL?
A
url_check() B
filter_var() with FILTER_VALIDATE_URL C
preg_match() D
url_validate()
Analysis & Theory
`filter_var($url, FILTER_VALIDATE_URL)` checks if the input is a valid URL.
What will be the output?
```
<?php
$email = 'example@domain.com';
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo 'Valid';
} else {
echo 'Invalid';
}
?>
```
A
Valid B
Invalid C
Error D
NULL
Analysis & Theory
The email 'example@domain.com' is valid, so it outputs 'Valid'.
What happens if an invalid email like 'abc@.com' is validated with `FILTER_VALIDATE_EMAIL`?
A
Returns true B
Returns false C
Returns the input value D
Throws an error
Analysis & Theory
`filter_var()` returns false if the email format is invalid.
Which PHP function checks if 'https://www.example.com' is a valid URL?
A
validate_url() B
check_url() C
filter_var($url, FILTER_VALIDATE_URL) D
url_match()
Analysis & Theory
`filter_var($url, FILTER_VALIDATE_URL)` validates URL format.
What does this code do?
```
<?php
$url = 'https://openai.com';
if (filter_var($url, FILTER_VALIDATE_URL)) {
echo 'Valid URL';
} else {
echo 'Invalid URL';
}
?>
```
A
Checks if the URL is reachable B
Checks if the URL format is valid C
Downloads the webpage D
Sends the URL to the browser
Analysis & Theory
It only checks the format of the URL, not whether it is reachable.
What happens if you pass a string 'hello' to `filter_var()` with `FILTER_VALIDATE_EMAIL`?
A
Returns 'hello' B
Returns false C
Returns true D
Throws an error
Analysis & Theory
The string 'hello' is not a valid email, so `filter_var()` returns false.
Can `FILTER_VALIDATE_EMAIL` check whether the email domain actually exists?
A
Yes B
No, it only checks the format C
Sometimes D
It depends on the browser
Analysis & Theory
It only validates the format, not the existence of the domain.
Which of the following is a valid email format?
A
example.com B
example@domain C
example@domain.com D
@domain.com
Analysis & Theory
`example@domain.com` is a correctly formatted email address.
Which of the following is a valid URL format?
A
www.example B
http:/example.com C
https://example.com D
example//.com
Analysis & Theory
`https://example.com` is a valid URL format.