PHP Exercises: Valid an email address
PHP: Exercise-38 with Solution
Write a PHP program to valid an email address.
Sample Solution: -
PHP Code:
<?php
function valid_email($email)
{
$result = trim($email);
if (filter_var($result, FILTER_VALIDATE_EMAIL))
{
return "true";
}
else
{
echo "false";
}
}
echo valid_email("[email protected]")."\n";
echo valid_email("abc#example.com")."\n";
?>
Sample Output:
true false
Flowchart:

PHP Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a PHP program to compute the sum of the prime numbers less than 100.
Next: Write a PHP program to get the size of a file.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
PHP: Tips of the Day
Mutates the original array to filter out the values specified
Example:
<?php function tips_pull(&$items, ...$params) { $items = array_values(array_diff($items, $params)); return $items; } $items = ['x', 'y', 'z', 'x', 'y', 'z']; print_r(tips_pull($items, 'y', 'z')); ?>
Output:
Array ( [0] => x [1] => x )
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises