preg_replace
. $1
, ; '$1'
.
preg_match
, , (#?\w+)
, preg_replace
, $value
:
$value['site_name'] = "www.thiswebsite.com";
$value['user_name'] = "user_123";
$value['signature'] = "something else";
$matches = array();
$pattern = "/<!-- (#?\w+) -->/i";
if (preg_match($pattern, $body, $matches)) {
if (array_key_exists($matches[1], $value)) {
$body = preg_replace($pattern, '<!-- ' . $value[$matches[1]] . ' -->', $body);
}
}
echo $body;