- print_r: documentation ( source)
- preg_match_all: documentation ( source)
<?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);