And just in case you're not using just single quotes:
<?php
function countLetters($string) {
if(!preg_match("/['\"](.*?)['\"]/", $string, $matches)) {
return FALSE;
}
for($i=0,$count=0,$max=strlen($matches[1]); $i < $max; $i++)
if(ctype_alpha($matches[1]{$i}))
$count++;
return $count;
}
$string = array("'Hello world!'", "C' EOF'", "A'ANEHA AWHENW#@(!!'", 'I have a "lovely bunch of" coconuts');
foreach($string as $str)
echo $str.': '.countLetters($str).'<br>';
?>
Output:
'Hello world!': 10
C' EOF': 3
A'ANEHA AWHENW#@(!!': 11
I have a "lovely bunch of" coconuts: 13