- preg_replace_callback: documentation ( source)
- htmlentities: documentation ( source)
<?php
$text = <<<TEXT
{swal title:='<span style="font-size: 16px;">INFORMATION</span>',html:='<span style="font-size: 14px;">Mask and sanitary pass are</span><b><span style="font-size: 14px; color: #FF0000;"> mandatory for all adults and kids from 12 to 17 to....</span></b><br /><br /><b>Thanks!</b>',icon:='info',confirmButtonText:='OK',iconColor:='#FF0000'}{/swal}
TEXT;
echo preg_replace_callback(
"~^{swal |\G(?!^)(?:(,?[a-z]+:=')(.*?)(')|}{/swal}(*SKIP))~mi",
function($m) {
return count($m) === 4 ? $m[1] . htmlentities($m[2]) . $m[3] : $m[0];
},
$text
);