Generating replacement strings with a callback function : preg_replace_callback « String « PHP






Generating replacement strings with a callback function

 
<?php
$html = 'The &lt;b&gt; tag makes text bold: <code>&lt;b&gt;bold&lt;/b&gt;</code>';
print preg_replace_callback('@<code>(.*?)</code>@','decode', $html);

function decode($matches) {
    return html_entity_decode($matches[1]);
}
?>
  
  








Related examples in the same category

1.Using preg_replace_callback() to Replace Patterns
2.Generating replacement strings with an anonymous function