note 38564 added to function.str-word-count
| From: | dj-canariasNOATSPAMwanadooDOTes at rn2 dot php dot net | Date: | Sat, 27 Dec 2003 17:05:14 +0000 |
| Subject: | note 38564 added to function.str-word-count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-62574@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:
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+38564
Delete -- http://master.php.net/manage/user-notes.php?action=delete+38564&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+38564&report=yes
Search -- http://master.php.net/manage/user-notes.php