Justin French wrote:
> It depends on what you define as a word, but let's take the simple
> approach of stripping HTML et al, and exploding the string on the
> spaces, then counting the array of words:
>
> $str = "This is my text that I want to count";
> $words = explode(' ', strip_tags($str));
It depends on what you define as a word, but let's take the simple approach
of stripping HTML et al, and exploding the string on the spaces, then
counting the array of words:
text that I want to count";
$words = explode(' ', strip_tags($str));
$count = count($words);
?>
Really no need for regex
if this is your SPECIFIC problem, putting a space at the beginning of $srch
will help, eliminating XAVAILABLE... but this will cause a problem with the
word AVAILABLE appearing at the start of the string, so temporarily put a
space at the start of the string:
this won't help if there are newlin
Greg Donald wrote:
>
> > I want to check a string and return the amount of words present
> > in it. These
> > strings could be quite large, some higher than 100,000
> > characters. I realize
> > I could explode the string on the whitespace and count the number
> > of values.
> > However, I'm no
> I want to check a string and return the amount of words present
> in it. These
> strings could be quite large, some higher than 100,000
> characters. I realize
> I could explode the string on the whitespace and count the number
> of values.
> However, I'm not sure this would be the most opti
5 matches
Mail list logo