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?
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')
strpos
will return 0, because code
is at the start of the string. 0 evaluates to false when using a loose comparison such as !
. What you need to do is make sure it doesn't have a strict evaluation to false:
if (strpos($headerInfo->subject, "code. $id") !== FALSE) {
echo true;
}