note 38565 deleted from function.str-word-count by nlopess

From: Date: Sat, 27 Dec 2003 19:40:31 +0000
Subject: note 38565 deleted from function.str-word-count by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-62582@lists.php.net to get a copy of this message
Note Submitter: dj-canarias NO AT SPAM wanadoo DOT es ---- On this function we can count words with several consecutive spaces, including any type of characters: Con esta función podemos contar palabras con varios espacios consecutivos, incluyendo cualquier tipo de caracteres: <?php function countWords($texto) { // If we want to process some text in HTML... // Si queremos procesar algún texto en HTML... $texto = ereg_replace("</P>"," ",$texto); $texto = ereg_replace("<BR>"," ",$texto); $texto = strip_tags($texto); $texto = trim($texto); $grupo = explode(" ",$texto); $hasta = count($grupo); $posicion = 0; $palabras = 0; while ($posicion < $hasta) { // It counts the words and rejects the consecutive spaces... // Cuenta las palabras y desecha los espacios consecutivos... if ($grupo[$posicion] != "") { $palabras++; } $posicion++; } return $palabras; } ?> .. K-iCO .. Tenerife (Spain) .. a big tropical paradise ..

« previous php.notes (#62582) next »