I get this specific string from a Mysql DB:
$string = "john('[email protected]'), frank('[email protected]'),simon('[email protected]')";
I need to have the string inserted in the following code:
$sendSmtpEmail = new SendinBlueClientModelSendSmtpEmail([
'subject' => 'Report',
'sender' => ['name' => 'sender', 'email' => '[email protected]'],
'to' => [
['name' => 'john', 'email' => '[email protected]'],
['name' => 'frank', 'email' => '[email protected]'],
['name' => 'frank', 'email' => '[email protected]']
],
'htmlContent' => $output
]);
Obviously, I need the 2d array containing associative rows in $sendSmtpEmail
, but how do I create it?
2
Answers
I am a bit late to answer but writing to help someone who came here searching. Hopefully this will help someone.
Complete script that will do is below down for copy
Use
preg_match_all()
to directly match one or more sequences of your formatted substrings. Use two capture groups, then map those data points to associative rows.Code: (Demo)