php - Replace REGEX variable with htmlentities? -
i have following bit of code replacement in preg_replace
"<div style="font-style:italic;margin:8px 6px">$2</div>"
is there way wrap htmlentities() around $2?
you can use preg_replace_callback()
:
function replace($matches) { return '<div style="font-style:italic;margin:8px 6px">' . htmlentities($matches[2]) . '</div>'; } preg_replace_callback('/pattern/', 'replace', $string);
Comments
Post a Comment