Example strings:
$string = "Buyer must enter coupon code 10OFF100 in shopping cart.";
$string = "Get $20 Off Auto Parts Order Over $150. Use Coupon code: GAPCJ20";
I need to extract the codes (10FF100 and GAPCJ20).
I was trying to create a preg_match to find "coupon code" and "coupon code:" and extract the phrase or word immediately after. Not having much luck myself or finding the reg expression.
Can some post the proper code please.
Thanks for the help.
Use this php code:
$arr = array("Buyer must enter coupon code 10OFF100 in shopping cart.", "Get $20 Off Auto Parts Order Over $150. Use Coupon code: GAPCJ20");
foreach ($arr as $s) {
preg_match('~coupon code\W+(\w+)~i', $s, $m);
var_dump($m[1]);
}
string(8) "10OFF100"
string(7) "GAPCJ20"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With