這裏是我的示例文本刪除文本之前和之後文本,我想 - PHP
------=_Part_564200_22135560.1319730112436
Content-Type: text/plain; charset=utf-8; name=text_0.txt
Content-Transfer-Encoding: 7bit
Content-ID: <314>
Content-Location: text_0.txt
Content-Disposition: inline
I hate u
------=_Part_564200_22135560.1319730112436
Content-Type: image/gif; name=dottedline350.gif
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=dottedline350.gif
Content-ID: <dottedline350.gif>
我需要能夠提取「我恨U」。
我知道我可以使用爆炸做
$body_content = garbled crap above;
$message_short = explode("------=_",$body_content);
echo $message_short;
的消息後,除去最後一部分,但我需要刪除的第一部分,在最後一部分沿。
因此,上述爆炸功能做什麼,我需要刪除結束 現在我需要的東西,說
FIND「內容處置:內聯」和之前 然後 找到任何刪除沿途「--- --- = _'並且隨後除去 然後 任何剩餘部分= $ message_short
echo $ message_short;
看起來像
我恨ü
任何幫助,將不勝感激。
感謝@Marcus
這是代碼,我現在和奇妙的作品。
$body_content2 = imap_qprint(imap_body($gminbox, $email_number));
$body_content2 = strip_tags ($body_content2);
$tmobile_body = explode("------=_", $body_content2);
$tmobile_body_short = explode("Content-Disposition: inline", $tmobile_body[1]);
$tmobile_body_complete1 = trim($tmobile_body_short[1]);
$tmobile_body_complete2 = explode("T-Mobile", $tmobile_body_complete1);
$tmobile_body_complete3 = trim($tmobile_body_complete2[1]);
我也討厭你。但是你可以使用[regular expression](http://regular-expressions.info)和['preg_match'](http://php.net/preg_match)來代替'explode'。但是,你有沒有完整的blob?那麼使用[PEAR mimeDecode](http://pear.php.net/package/Mail_mimeDecode)會更容易。 – mario
你可以在雙線上試試strstr。 – hafichuk