<?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
(
)
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
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
(
)