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

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -