English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I don't want to count the words in a text box. I want to pass an http reference and return the number of words on the page.

2006-10-23 08:58:25 · 3 answers · asked by jack b 3 in Computers & Internet Programming & Design

3 answers

I can't think of an easy way to do it using javascript, but if you can use a server side script it shouldn't be too difficult.

In PHP it would be:

$string = "a lot of text, the content of your page or whatever";
$string = striptags( $string );//remove any html tags that would throw this off
$string = preg_replace("/\w+/", " ", $string);//change all white space characters, or groups of white space to one space
$string = trim($string);//remove any leading or trailing white space
$array = explode(" ",$string);//change the string to an array broken on spaces
$wordCount = count($array);

2006-10-23 09:32:41 · answer #1 · answered by John J 6 · 0 0

Use a mix of substr(), indexOf() and the size residences with a loop to loop for the time of the string and split it up at area characters right into a string array (or in simple terms have a counter for a fashion many circumstances it became split).

2016-10-16 07:42:36 · answer #2 · answered by benner 4 · 0 0

nope, you would have to use the innerText property and analise the string yourself, maybe use the split function to count words

2006-10-23 09:09:17 · answer #3 · answered by Deep Thought 5 · 0 0

fedest.com, questions and answers