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

java - How to Configure JAXRS and Spring With Annotations -

visual studio - TFS will not accept changes I've made to a Java project -

php - Create image in codeigniter on the fly -