如果在foreach循环char中的语句检查
问题描述:
I need to only run the foreach on iterations that find a currency symbol. Currently, I have this -
$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]);
which I can in turn get the player ID from the string
<a href = "http://www..com/.php?XID=1826888">saeed</a> donated $800,000,000 to the faction
However, as it stands, I need to only check strings that include the money donation, $800,000,000.
Included in the output can be such things as
<a href = "http://www..com/.php?XID=2023426">French_</a> donated 1 x First Aid Kit to the faction
I need to not run the foreach info on strings such as this.
答
from what i understand, you could do something like this :
<?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]);
}
}
But still, i'm not sure what you are looking for.