【问题标题】:Sorting strings and create case based on keywords对字符串进行排序并根据关键字创建大小写
【发布时间】:2017-01-27 10:00:19
【问题描述】:

我需要检查 gmail 收件箱并阅读每封电子邮件的电子邮件正文,并根据关键字“计费和加载”在 CRM 中创建一个案例,我有一个用于从 Gmail 读取邮件的工作代码,但排序一直是问题。

我有这个代码

 foreach($emails as $email) {

        $headerInfo = imap_headerinfo($connection,$email);
        $message= imap_fetchbody($connection , $email,1);

        if (preg_match('/Bill|load/', $message)) {
            if (strpos($message, 'Bill')) {
                echo 'billing related issue';
            }elseif (strpos($message, 'load')) {
                echo 'Loading related issue';
            }
        }else echo 'doesn\'t exists</br>';
     }

此代码检查所有邮件,查找关键字,但它会检查 Billing 或 Loading,而不是同时检查两者。请帮帮我。

【问题讨论】:

  • 这里使用preg_match 没有意义。使用strpos 检查是否有Bill。检查是否有load。将结果存储在单独的变量中。检查它们的值并编写适当的逻辑。
  • @WiktorStribiżew:对不起,。那是我无法做到的,我不明白如何将它们存储在单独的变量中并使用。

标签: php string loops if-statement


【解决方案1】:

这里不需要preg_match()strpos() 将以所需的方式工作:-

 foreach($emails as $email) {
    $headerInfo = imap_headerinfo($connection,$email);
    $message= imap_fetchbody($connection , $email,1);
    if (strpos($message, 'Bill')!== false && strpos($message, 'load') === false) {
        echo 'billing related issue';
    }else if (strpos($message, 'Bill') === false && strpos($message, 'load') !== false) {
        echo 'Loading related issue';
    }else if(strpos($message, 'Bill') !== false && strpos($message, 'load') !== false){
        echo 'Loading/Billing related issue';
    }else echo 'does\'t exists</br>';
 }

【讨论】:

  • @SugarAPI 很高兴为您提供帮助。:):):)
  • 已标记,谢谢
猜你喜欢
  • 2010-10-08
  • 2019-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-07
  • 2014-04-27
相关资源
最近更新 更多