I have a custom PHP script with template text that looks like this
Color: [option]color[/option]<br />
[if option="manufacturer"]<br />
Manufacturer: [option]manufacturer[/option]<br />
[/if]<br />
Price: [option]price[/option]
I have used preg_replace_callback to successfully replace [option]color[/option] and [option]price[/option] with real values like White and $10.00.
I am using this code for simple [option] shortcodes:
$template = preg_replace_callback('!\[option](\w+)\[\/option\]!',
function ($matches)
{
//Here I get a value of color, price, etc
...
return $some_value;
},
$template);
But I just can`t figure out what to do with IF statements... It should check if the manufacturer is set and then replace [option]manufacturer[/option] and of course also remove the opening and closing if line.
Result output should be
Color: White<br />
Manufacturer: Apple<br />
Price: $10.00
Or if there is no manufacturer defined it should be
Color: White<br />
Price: $10.00