note 40119 added to function.str-word-count

From: Date: Sun, 22 Feb 2004 14:06:07 +0000
Subject: note 40119 added to function.str-word-count
Groups: php.notes 
Request: Send a blank email to php-notes+get-65538@lists.php.net to get a copy of this message
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; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.str-word-count.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40119 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40119&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40119&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#65538) next »