One of the things that irks me most about programmers getting involved with marketing is that most of them just don't know grammar.  SEO Black Hat mentioned "Google are," I mentioned "then vs. than," and now I'll mention one more thing — "a vs. an."  This one is a little different.  Most people know this rule intuitively.  But programmers frequently get lazy and do not look programmatically at the following word to decide which indefinite article to use.  Being a programmer makes me slightly more forgiving, but this still looks bad.  After I release this code, there are no more excuses:

<?

function aOrAn($next_word)
{
    
$_an = array('hour''honest''heir''heirloom');
    
$_a = array('use''useless''user');
    
$_vowels = array('a','e','i','o','u');
    
    
$_endings = array('ly''ness''less''lessly''ing''ally''ially');
    
$_endings_regex implode('|'$_endings);
    
    
$tmp preg_match('#(.*?)(-| |$)#'$next_word$captures);
    
$the_word = trim($captures[1]);
    
//$the_word = Format::trimString(Utils::pregGet('#(.*?)(-| |$)#', $next_word, 1));
    
    
$_an_regex implode('|'$_an);
    if (
preg_match("#($_an_regex)($_endings_regex)#i"$the_word)) {
        return 
'an';
    }
    
    
$_a_regex implode('|'$_a);
    if (
preg_match("#($_a_regex)($_endings_regex)#i"$the_word)) {
        return 
'a';
    }
    
    if (
in_array(strtolower($the_word{0}), $_vowels)) {
        return 
'an';    
    }
    
    return 
'a';
}

?>

This code may not be bulletproof, but it nails most of the major rules and exceptions.  So if I see one more lazy PHP programmer making this stupid mistake, I'm just closing the window, OK? :) 

Tell an amigo:
  • Sphinn
  • Digg
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Facebook



Related posts:
A (not so simple) method to add rel="nofollow" to links I wrote this script so that I can run it...
A Little Grammar Lesson A major copywriting concern becomes manifest when one realizes that...
Checking for Dead Links Automatically This neat little class can return the HTTP status code...
The Proper Procedure for Changing Hosting Companies (It's really not always so simple … ) Should the need exist to change hosting companies, the process...