Assuming you start with this:
$mask = "%name% (%user_count%) - %acyr% - %audience%";
$data = [
'%name%' => $group['name'],
'%user_count%' => $group['user_count'],
'%acyr%' => $group['acyr'],
'%audience%' => $group['audience'],
];
$result = strtr($mask, $data);
What is the best way of reversing this such that you transform $result into the following defined and populated variables?
(Also bear in mind that the order of $mask could change.)
$name = '?';
$user_count = '?';
$acyr = '?';
$audience = '?';
I have tried using preg_split() / list() but I want $mask to govern the order of the variables without having to convert it into a complicated regex.
Basically I need a simple method of parsing/splitting a string into multiple variables based on a mask containing placeholders.
The mask can be changed by altering the order of the placeholders or adding new punctuation yet the logic is flexible enough to generate the variables.
PHP code demo