例如,如果我有这篇文章(string):
..。Inky与目前在Linux上提供的其他电子邮件应用程序非常不同--不仅在外观上,而且在功能上也是如此。 例如,Inky在设置过程中扫描收件箱和联系人,找出哪些信息对您来说更“重要”,哪些不重要。信息旁边的墨汁越暗,Inky就越认为它重要。..。
来源: http://www.omgubuntu.co.uk/2013/05/inky-pens-linux-support-on-roadmap
我想数一个具体的词。因此,结果是:
字:
墨(3字)
电子邮件(1字)
Linux (1字)
..。
等
我应该在php中使用什么功能?
发布于 2013-05-05 06:53:35
<?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'];
?>只是一个粗略的例子,但希望它能让你走上正确的道路。
https://stackoverflow.com/questions/16382078
复制相似问题