Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP脚本,用于为大于一组数字的每个值解析HTML电子邮件_Php_Parsing_Email - Fatal编程技术网

PHP脚本,用于为大于一组数字的每个值解析HTML电子邮件

PHP脚本,用于为大于一组数字的每个值解析HTML电子邮件,php,parsing,email,Php,Parsing,Email,我有一个PHP脚本正在解析的订单确认html电子邮件。该脚本成功地完成了一些事情,但我不知道如何让它通过电子邮件搜索所有产品价格,然后在值大于500英镑时设置标志 基本上,如果订单超过500英镑,我希望脚本向我发送电子邮件提醒 以下是我到目前为止的情况$正文是HTML电子邮件的内容。我知道这部分的工作原理与其他规则的设置相同。我认为我的问题是preg_match的$pattern规则-我认为它没有正确识别价格值 是否有一种方法可以搜索$body以查找任何格式为£xx.xx(其中每个x都是一个数字

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

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

以下是我到目前为止的情况$正文是HTML电子邮件的内容。我知道这部分的工作原理与其他规则的设置相同。我认为我的问题是preg_match的$pattern规则-我认为它没有正确识别价格值

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

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);
}

}
if(stristr($body,'Order Confirmation')!==false){
$string=$body;
$pattern='/^[0-9]{1,}$/';
预匹配($pattern,$string,$matches);
$temp=数组过滤器($matches,function($value){
返回$value>=500;
});
如果($temp>=1)
{
$headers=“内容类型:text/html\r\n”;
$headers.=“发件人:机器人”;
邮件('joe@blogs.com“,”互联网订单价值超过500英镑“,$body,$headers);
}
}

我想这会满足你的要求。如果您复制并粘贴到具有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>

{1,}
可以用
+
简化。