note 38564 deleted from function.str-word-count by vincent
| From: | vincent@php.net | Date: | Sat, 27 Dec 2003 17:58:02 +0000 |
| Subject: | note 38564 deleted from function.str-word-count by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-62576@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:
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 ..