0

我有一个 PHP 脚本正在解析的订单确认 html 电子邮件。该脚本成功地做了一些事情,但我不知道如何让它通过电子邮件搜索所有产品价格,然后在价值大于 500 英镑时设置一个标志。

基本上,如果订单超过 500 英镑,我希望脚本向我发送电子邮件提醒。

以下是我到目前为止所拥有的。$body 是 HTML 电子邮件的内容。我知道这部分工作正常,因为其他规则设置得很好。我认为我的问题是 preg_match 的 $pattern 规则 - 我认为它没有正确识别价格值。

有没有一种方法可以让我在 $body 中搜索格式为 £xx.xx(每个 x 是一个数字)的任何内容,并为它找到的每个大于 £500 的值加 1 到 $temp?我无法解决这个问题...

if (stristr($body,'Order Confirmation') !== false) {

    $string = $body;

    $pattern = '/^[0-9]{1,}$/';

    preg_match ($pattern, $string, $matches);

    $temp =  array_filter($matches, function($value) {
        return $value >= 500;
    });

if ($temp >= 1)
{
    $headers = "Content-type: text/html \r\n";
    $headers .= "From: Robot<robot@robot.com>";
    mail('joe@blogs.com','Internet Order Value Over £500', $body, $headers);
}

}
4

1 回答 1

0

我认为这会做你想要的。如果您复制并粘贴到具有 php 扩展名的文件中,该代码应该可以工作。您必须为您的脚本稍微编辑它。

<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" media="screen" href="bla.css" >
    <script type="text/javascript" src="https:ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>

<body>

<?php

$string = "lots of things here oh look a price in bold <b>£656.00</b> then more things oh wow";

$pattern = '~<b>£([^<]*).([^<]*)</b>~'; //pattern to find the price in-between the <b></b> tags in $string

preg_match ($pattern, $string, $matches);

$price = substr($matches[0],5); // removes the <b>£ bits from the match if present

if ($price >= 500.00) // if statement to determine if greater than a value
{
echo "value is greater than £500";
    }

?>

</body>
</html>
于 2012-06-29T08:39:08.023 回答