Nothing of this worked for me. I think countwords() is very encoding dependent. This is the code for win1257. For other layots you just need to redefine the ranges of letters...
<?php
function countwords($text){
$ls=0;//was it a whitespace?
$cc33=0;//counter
for($i=0;$i<strlen($text);$i++){
$spstat=false; //is it a number or a letter?
$ot=ord($text[$i]);
if( (($ot>=48) && ($ot<=57)) || (($ot>=97) && ($ot<=122)) || (($ot>=65) && ($ot<=90)) || ($ot==170) ||
(($ot>=192) && ($ot<=214)) || (($ot>=216) && ($ot<=246)) || (($ot>=248) && ($ot<=254)) )$spstat=true;
if(($ls==0)&&($spstat)){
$ls=1;
$cc33++;
}
if(!$spstat)$ls=0;
}
return $cc33;
}
?>