Example #1 Validating email addresses with filter_var()
<?php
$email_a = 'joe@example.com';
$email_b = 'bogus';
if (filter_var($email_a, FILTER_VALIDATE_EMAIL)) {
echo "This (email_a) email address is considered valid.";
}
if (filter_var($email_b, FILTER_VALIDATE_EMAIL)) {
echo "This (email_b) email address is considered valid.";
}
?>
위 예제의 출력:
This (email_a) email address is considered valid.
Example #2 Validating IP addresses with filter_var()
<?php
$ip_a = '127.0.0.1';
$ip_b = '42.42';
if (filter_var($ip_a, FILTER_VALIDATE_IP)) {
echo "This (ip_a) IP address is considered valid.";
}
if (filter_var($ip_b, FILTER_VALIDATE_IP)) {
echo "This (ip_b) IP address is considered valid.";
}
?>
위 예제의 출력:
This (ip_a) IP address is considered valid.