如何匹配出现在 php 中的字符的频率


How to match the frequency of the characters appear in php

我想

回到自动邮件功能,我想是这样:指定关键字的一些特征,然后计算出关键字在文本中出现的百分比,如果匹配,我找到具体的消息内容进行回复。如客户邮件写着:您好,我想找这封信,我还没收到。那么我的关键词是:信,没有收到我是如何得出这些关键字出现在邮件客户端内容中

的频率的

使用 substr_count()

<?php
$mail = 'Hello, I want to find this letter, I have not received. Waiting for you to resend the letter.';
$keywords = array(
  'letter',
  'not received'
);
foreach($keywords as $keyword) {
  echo "Keyword '$keyword': found " . substr_count($mail, $keyword) . "'n";
}

输出

关键字"信件":找到 2
关键字"未收到":找到 1