我只需要在找到貨幣符號的迭代中運行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信息。
[_ **不要使用正則表達式,使用XML解析器。** _](http://stackoverflow.com/a/1732454/510036) – Qix
該問題不是正則表達式。我需要在foreach中運行if語句來檢查該行是否有$符號,否則不要運行foreach。 – saeed
@saeed,爲什麼不使用像\^\ $(。+)\這樣的正則表達式來檢查一個字符串是以$開頭呢還是簡單地用PHP函數$ string.startsWith('$');並繼續您的操作與結果? – Nicolas