0

例如,如果我有这篇文章(字符串):

...

Inky 与 Linux 上目前可用的任何其他电子邮件应用程序都非常不同——不仅在外观上,而且在功能上。

例如,Inky 会在设置期间扫描您的收件箱和联系人,以确定哪些邮件对您来说更“重要”,哪些不是。消息旁边的墨滴越深,Inky 认为它越重要。

...

[来源:http://www.omgubuntu.co.uk/2013/05/inky-pens-linux-support-on-roadmap]

我想数一个特别的词。所以,结果是:

单词:

漆黑(3个字)

电子邮件(1 个字)

Linux(1 个字)

...

ETC

我应该使用php中的什么函数?

4

1 回答 1

1
<?php
  $string = <<<_STRING_
  Inky is pretty unlike any other email app currently available on Linux – not just in looks but also in features.

  For example, Inky scans your inbox and contacts during set-up to work out which messages are more likely to be ‘important’ to you, and which aren’t. The darker an ink drop next to a message the more important Inky considers it.
_STRING_;
$word_count = str_word_count($string, 1);
$search_for = array('Inky', 'linux', 'email');
foreach ($search_for as $item) {
  $count[$item] = 0;
}

foreach ($word_count as $key => $word) {
  if (in_array($word, $search_for)) {
    $count[$word]++;
  }
}
print $count['Inky'];
print $count['linux'];
print $count['email'];
?>

只是一个粗略的例子,但希望它能让你走上正确的道路。

于 2013-05-05T06:53:35.263 回答