I have to determine all short tags like [field id=”key1″] in the string, get the keys from the short tags to use them to get the values like $fields[“key1”], then replace in the string the short tag to the values.
For Example:
'Phone number: [field id="tel"], Name: [field id="name"]'
should become to
'Phone number: 123456789, Name: John'
How can I do that with preg_replace?
$fields = ["tel" => "123456789", "name" => "John",];
$string = 'Phone number: [field id="tel"], Name: [field id="name"]';
$new_string = preg_replace(?, $fields["$1"], $string);
//output $new_string = "Phone number: 123456789, Name: John"