fork(2) download
  1. <?php
  2.  
  3. $stopwords = array('потому что',' Я','ты','люб');
  4. $text = "потому что Любимый мой! бы то ни было Я Я Я хочу сказать тебе, что ты у меня самый любимый!";
  5.  
  6. $summ=0;
  7.  
  8. foreach ($stopwords as $slovo)
  9. {
  10. if(preg_match_all ('/\b'.preg_replace('/\s+/','\s+',preg_quote(trim($slovo))).'\b/us', $text, $matches)){
  11. printf ("word `%s` occurs %d times\n",$slovo,count($matches[0]));
  12. $summ+=count($matches[0]);
  13. } else {
  14. printf ("no word `%s` found\n",$slovo);
  15. }
  16. }
  17. printf ("totally found `%s` stopwords\n",$summ);
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
word `потому что` occurs 1 times
word ` Я` occurs 3 times
word `ты` occurs 1 times
no word `люб` found
totally found `5` stopwords