首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果我想数一下我在一篇文章中找到的具体单词,那又有什么用呢?

如果我想数一下我在一篇文章中找到的具体单词,那又有什么用呢?
EN

Stack Overflow用户
提问于 2013-05-05 06:42:54
回答 1查看 37关注 0票数 0

例如,如果我有这篇文章(string):

..。Inky与目前在Linux上提供的其他电子邮件应用程序非常不同--不仅在外观上,而且在功能上也是如此。 例如,Inky在设置过程中扫描收件箱和联系人,找出哪些信息对您来说更“重要”,哪些不重要。信息旁边的墨汁越暗,Inky就越认为它重要。..。

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

我想数一个具体的词。因此,结果是:

字:

墨(3字)

电子邮件(1字)

Linux (1字)

..。

我应该在php中使用什么功能?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-05 06:53:35

代码语言:javascript
复制
<?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'];
?>

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16382078

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档