I'm trying to find two patterns in a text file with PHP.
Text file looks like this:
[transactionDetails] => wsTransactionDetail Object
(
[sharesAmount] =>
[sharesNumber] =>
[amount] => 33450
[commerceCode] => 1234567890
[buyOrder] => 123321
)
[detailOutput] => wsTransactionDetailOutput Object
(
[authorizationCode] => 001122
[paymentTypeCode] => VD
[responseCode] => 0
[sharesNumber] => 0
[amount] => 33450
[commerceCode] => 1234567890
[buyOrder] => 123321
)
And my PHP code looks like this:
$pattern1 = preg_quote("authorizationCode", '/');
$pattern2 = preg_quote("amount", '/');
$pattern = "/^.*($pattern1).*\$|($pattern2).*\$/m";
if(preg_match_all($pattern, $contents, $matches)){
echo "Founds:\n";
echo implode("\n", $matches[0]);
}
It works well but I'm getting [amount] => 33450 two times because "amount" is two times in text file.
I need to get "amount" and "authorizationCode" values only inside in this part of the text file:
[detailOutput] => wsTransactionDetailOutput Object
(
[authorizationCode] => 001122
[paymentTypeCode] => VD
[responseCode] => 0
[sharesNumber] => 0
[amount] => 33450
[commerceCode] => 1234567890
[buyOrder] => 123321
)
Could someone help me please?? I'll be grateful.
I think my problem is in regular expression:
/^.*($pattern1).*\$|($pattern2).*\$/m
I should modify that to find only patters inside [detailOutput] => wsTransactionDetailOutput Object(
Thanks you!