<?php

header
('Content-Type: text/plain; charset=urf-8');

$count null;
for ( 
$i 0$i 10000$i++ )
{
    
$start microtime(true);
    
    
$str 'if (!preg_match(#^[A-Za-z_]+$#, $text)) { ';
    
    
/*if (!preg_match('#^[A-Za-z_]+$#', $str))
    {
        // has bad characters
        $str = $str;
    }*/
    
    
$str preg_replace('/[^a-z_]/i'''$str); // remove the "i" if you don't want A-Z to be matched as well
    //$str = preg_replace('/[^a-zA-Z_]/', '', $str);
    
$count[] = 10*(microtime(true)-$start);
}

echo 
'String: ' $str "\n";
echo 
'Average: ' . (array_sum($count)/count($count)) . "\n";
//echo 'Time taken: ' . ($end - $start);

?>