PHP/String/str word count — различия между версиями

Материал из Web эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 07:07, 26 мая 2010

mixed str_word_count ( string str [, int count_type [, string char_list]] ) returns the number of words in a string

 
<?
    $str = "This is a test, only a test, and nothing but a test.";
    $a = str_word_count($str, 1);
    $b = str_word_count($str, 2);
    $c = str_word_count($str);
    print_r($a);
    print_r($b);
    echo "There are $c words in the string\n";
?>



str_word_count-2.php

 
<?php
$summary = <<< summary
this is a test. this is a test. this is a test. this is a test. this is a test. this is a test.
this is a test. this is a test. this is a test. this is a test. this is a test. this is a test.
this is a test. this is a test. this is a test. this is a test. this is a test. this is a test.
summary;
   $words = str_word_count($summary,2);
   $frequency = array_count_values($words);
   print_r($frequency);
?>



str_word_count.php

 
<?php
$summary = <<< summary
this is a test. this is a test. this is a test. this is a test. this is a test. this is a test.
this is a test. this is a test. this is a test. this is a test. this is a test. this is a test.
this is a test. this is a test. this is a test. this is a test. this is a test. this is a test.
summary;
   $words = str_word_count($summary);
   echo "Total words in summary: $words";
?>