Taking the title of the thread into account, a wee optimisation to LordShryku's code could be made by adding a break.
$string = 'a1a2a3)~';
$digits = 0;
$characters = 0;
for($i=0;$i<strlen($string);$i++) {
if(ctype_digit($string{$i})) { $digits++; }
if(ctype_alpha($string{$i})) { $characters++; }
if($digits>=3 && $characters>=3) break;
}
If you've found at least three digits and three letters, you don't need to keep looking! It's probably not much of a saving unless the line is potentially a fair bit longer than six characters.
(And - just because there's more than one way to do it, not because it's necessarily a good idea - with regexps!)
$count_digits = preg_match_all('/[0-9]/',$string);
$count_letters = preg_match_all('/[a-z]/i', $string);