⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 word_table.php

📁 对于这种语言是比较的麻烦的了..你自己慢慢体会了..好难说清楚的了
💻 PHP
字号:
<<html >
<head> <title> word_table.php </title>
</head>
<body>
<?php

// Function splitter
//  Parameter: a string of text containing words and punctuation
//  Returns: an array in which the unique words of the string are
//           the keys and their frequencies are the values.

function splitter($str) {

// Create the empty word frequency array

  $freq = array();

// Split the parameter string into words

  $words = preg_split("/[ .,;:!?]\s*/", $str);

// Loop to count the words (either increment or initialize to 1)

  foreach ($words as $word) {
    $keys = array_keys($freq);
    if(in_array($word, $keys))
      $freq[$word]++;
    else
      $freq[$word] = 1;
  }

  return $freq;
} #** End of splitter

// Main test driver

  $str = "apples are good for you, or don’t you like apples? 
or maybe you like oranges better than apples";

// Call splitter

  $tbl = splitter($str);

// Display the words and their frequencies

  print "<br /> Word Frequency <br /><br />";
  $sorted_keys = array_keys($tbl);
  sort($sorted_keys);
  foreach ($sorted_keys as $word)
    print "$word $tbl[$word] <br />";
?>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -