I am just trying to make it so that {string} will turn into the value of the $string variable.
For example, consider I have the following variables:
$car = 'Audi';
$speed = 'Fast';
$sentence = "The {car} goes {speed}";
I want this to output: The Audi goes Fast
Here is my code which is not working:
$setting['leads_low_subject'] = '{dealer_name} has {leads_left} leads left!';
$dealer_name = 'My Test Dealer';
$leads_left = 6;
$subject = preg_replace('/\{([a-z]+)\}/e', "$$1", $setting['leads_low_subject']);
echo $setting['leads_low_subject'].'<br />';
echo "$subject";
This is echoing:
{dealer_name} has {leads_left} leads left!
{dealer_name} has {leads_left} leads left!
When it should be echoing:
{dealer_name} has {leads_left} leads left!
My Test Dealer has 6 leads left!
Why is it not working properly?
{dealer_name}has an underscore, but you match[a-z]+, might try with[a-z_]+or\w+where\wis a shorthand to[A-Za-z0-9_]emodifier is deprecated. Usepreg_replace_callback()as a replacement.