3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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);
based on e9mNV
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0rc3
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 ( )