drlh197610 2018-08-09 13:07
浏览 168

PHP - 带空格的strpos()

imap subject = "code. 115 is your id"

I tried using below one but didnt worked.

$headerInfo = imap_headerinfo($connection);
if (!strpos($headerInfo->subject, "code. $id")) {
    echo true 
}

$headerInfo = imap_headerinfo($connection);
if (!strpos($headerInfo->subject, "code.$id")) {
    echo true 
}

How can I fetch that?

  • 写回答

2条回答 默认 最新

  • douduoquan2824 2018-08-09 13:10
    关注

    You could extract the $id using a regular expression capture group.

    <?php
    $id = getId('imap subject = "code. 115 is your id"'); // is 115
    $id = getId('imap subject = "code.115.00 is your id"'); // is 115
    
    function getId($subject) {
        $r = [];
        if (preg_match("/code\. ?([0-9]+)(\.00)? is your id/", $subject, $r)) {
            return $r[1];
        }
        else {
            throw new Exception("Couldn't match subject");
        }
    }
    

    Now you only need to check if this $id is your id :)

    $id = getId($headerInfo->subject);
    if ($id == '119')
    
    评论

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制