如果在foreach循环char中的语句检查

时间:2016-10-18 19:19:57

标签: php regex foreach

我只需要在找到货币符号的迭代上运行foreach。目前,我有这个 -

$transferid = $key;
$donation1 = $value["news"];
$donationcomma = getStringBetween($donation1,$from,$to);
$donation = str_replace(',', '', $donationcomma);
$playeridregex = preg_match("/XID=(.*)\"/", $donation1, $playerid);
$playerid1 = preg_replace("/[^A-Za-z0-9'-]/","",$playerid[1]);

我可以从字符串中获取玩家ID

<a href = "http://www..com/.php?XID=1826888">saeed</a> donated $800,000,000 to the faction

但是,按照目前的情况,我只需检查包含捐款的字符串,即800,000,000美元。

输出中包含的内容可以是

 <a href = "http://www..com/.php?XID=2023426">French_</a> donated 1 x First Aid Kit to the faction

我不需要在诸如此类的字符串上运行foreach信息。

1 个答案:

答案 0 :(得分:0)

据我所知,你可以做这样的事情:

<?php
foreach($values AS $key=>$value) {
    if(preg_match('/^(\$)(.+)/', $value) == 1) { 
        $transferid = $key;
        $donation1 = $value["news"];
        $donationcomma = getStringBetween($donation1,$from,$to);
        $donation = str_replace(',', '', $donationcomma);
        $playeridregex = preg_match("/XID=(.*)\"/", $donation1, $playerid);
        $playerid1 = preg_replace("/[^A-Za-z0-9'-]/","",$playerid[1]);
    }
}

但是,我仍然不确定你在寻找什么。