dqrdlqpo775594 2013-07-26 09:32
浏览 45
已采纳

从文本中提取数据(字符串)

I'am using email2http to post into my status file !

When I receive the mail and get it posted to my status file , I was to extract some data and assign them to some values

I mean , I made that !

<?php
$body = $_POST['body'];

function plog($errorMsg)
{
    $filename = "email.txt";
    if ($handle = fopen($filename, 'a+')) {
    if (fwrite($handle, $errorMsg) === FALSE) {
        echo "Cannot write to file ($filename)";
    }
}
else {
    echo "Cannot open file ($filename)";
}
fclose($handle);
}
$msgBody .= "$body
";
plog($msgBody."
");
?>

the $_POST['body'] contains the text sent from a mail

lets say all the mails come like this type :

The amount of 5 USD has been deposited to your account. Memo: Shopping Cart Payment. Exchange ID :1317 . Date: 23:07 25.07.13. Batch: 28808853.

So I want to get thos variables :

$amout=5;

$id=1317;

$date=23:07 25.07.13;

$batch=28808853;

  • 写回答

2条回答 默认 最新

  • dongtun2459 2013-07-26 09:38
    关注

    I think you can try to extract data with explode, if the mails are all time the same.

    For example :

    $var = explode('amount of ', $_POST['body']);
    $var2 = explode('USD', $var[1]);
    $amount = $var2[0];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改