在数组中查找文本使用preg_match

时间:2016-05-26 14:06:46

标签: php arrays preg-match

我有代码:

Array
(
    [0] => Array
        (
            [Time] => 05/24/2016 05:24
            [Type] => Income
            [Batch] => 134410438
            [Currency] => USD
            [Amount] => 60.00
            [Fee] => 0.00
            [Payer Account] => 123213
            [Payee Account] => 512321
            [Memo] => ,Received Payment 60.00 USD from account 123213. Memo: API Payment. EXCHANGE755531.
        )

如何在此数组中找到文本“EXCHANGE755531”使用preg_match?

1 个答案:

答案 0 :(得分:0)

preg_match("/(\w+)\.$/", $arr[0]["Memo"], $match);
Echo $match[1];
// This only works if the word is the last word before "."


preg_match("/Memo: API Payment\.\s+(\w+)/", $arr[0]["Memo"], $match);
Echo $match[1];
//this only works if "Memo: API Paayment." is static.


preg_match("/(EXCHANGE\d+)/",  $arr[0]["Memo"], $match);
// this one searches for the word "EXCHANGE" and digits after

选择最适合你的那个。