function strlenth($str) { $arr = str_split($str); $count = 0; foreach($arr as $val) { $ascii = ord($val); if(!( $ascii == 209 || ($ascii >= 212 && $ascii <= 218 ) || ($ascii >= 231 && $ascii <= 238 ))) $count += 1; } return $count; }
$str = "นครราชสีมา ครับ"; echo strlenth($str);