Forum Moderators: coopster
if (preg_match($pattern, $name)) {
$status = TRUE;
}Syntax parser would have caught that right away.
You are strongly encouraged to always use curly braces even in situations where they are technically optional. Having them increases readability and decreases the likelihood of logic errors being introduced when new lines are added.[pear.php.net...]
Sound advice!
If you are a beginner, though, you could technically use either method, but I believe the curly braces is the better, easier, easier to read method. IMHO.
function checkName ($name)
{
return preg_match('/^[A-Za-z]+$/', $name);
}
Or, if you want to ensure checkName returns a real boolean, rather than the 0 or 1 preg_match returns:
return (bool)preg_match('/^[A-Za-z]+$/', $name); return !!preg_match('/^[A-Za-z]+$/', $name); return preg_match('/^[A-Za-z]+$/', $name) ? true : false; return preg_match('/^[A-Za-z]+$/', $name) == 1; But that's just style, and your preferences undoubtedly vary from my own. :)