Generating replacement strings with an anonymous function : preg_replace_callback « String « PHP






Generating replacement strings with an anonymous function

 
<?php
$callbackFunction = create_function('$matches','return html_entity_decode($matches[1]);');
$fp = fopen('html-to-decode.html','r');
while (! feof($fp)) {
    $line = fgets($fp);
    print preg_replace_callback('@<code>(.*?)</code>@',$callbackFunction, $line);
}
fclose($fp);
?>
  
  








Related examples in the same category

1.Using preg_replace_callback() to Replace Patterns
2.Generating replacement strings with a callback function