<?php
function extractVars($pattern){
//Extract if function
$array_vars = [];
$rgx = '/^(?<startOfS>.*?)\{=IF\((device=mobile|audience IN\(.*?\)),(.*?)\):(.*?)\}(?<endOfS>.*?)$/';
preg_match_all($rgx, $pattern, $matches, PREG_SET_ORDER, 0);
print_r($matches);
return $array_vars;
}
$var = extractVars(" Get The Best Shoes At The Best Price. {=IF(device=mobile,Free Shipping on Mobile Orders!):Buy Now!}");
print_r($var);
Array
(
[0] => Array
(
[0] => Get The Best Shoes At The Best Price. {=IF(device=mobile,Free Shipping on Mobile Orders!):Buy Now!}
[startOfS] => Get The Best Shoes At The Best Price.
[1] => Get The Best Shoes At The Best Price.
[2] => device=mobile
[3] => Free Shipping on Mobile Orders!
[4] => Buy Now!
[endOfS] =>
[5] =>
)
)
Array
(
)