Building A PHP-Based Mail Client (part 1) - Fully Function-al
(Page 4 of 7 )
Before moving on, a quick word about the "functions.php" file include()d in the script you just saw.
"functions.php" is a separate file containing useful function definitions. Every time I write a function that might come in useful elsewhere in the application, I move it into "functions.php" and include that file in my script.
An example of this is the validate_email() function used in the script above - here's what it looks like:
<?
// check if email address is valid
function validate_email($val)
{
if($val != "")
{
$pattern =
"/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/";
if(preg_match($pattern, $val))
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
?>
Again, this is fairly simple - I'm using PHP's pattern
matching capabilities to verify that the email address supplied conforms to the specified pattern. The function returns true or false depending on whether or not the match was successful.
Next: Opening Up >>
More PHP Articles
More By icarus, (c) Melonfire