note 38565 added to function.str-word-count

From: Date: Sat, 27 Dec 2003 17:09:50 +0000
Subject: note 38565 added to function.str-word-count
Groups: php.notes 
Request: Send a blank email to php-notes+get-62575@lists.php.net to get a copy of this message
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 .. ---- Manual Page -- http://www.php.net/manual/en/function.str-word-count.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38565 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38565&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38565&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#62575) next »