Skip to main content

Posts

Showing posts with the label preg_replace_callback

Perl-style regular expressions( preg_replace_callback)

• preg_replace_callback() -                                            With preg_replace(), the function itself is responsible for handling the replacement procedure. With preg_replace_callback(), the handling of the replacement procedure is handed off to another function to take care of. The syntax is identical to preg_replace() except where the replacement text would be located, a function name is present. This function is responsible for handling any of the replacement changes to the text that matches the pattern searched. <?php $text = "Dear <pnm>S</pnm>Ortiz,<br>&nbsp;&nbsp;&nbsp;&nbsp;I would like to thank you and <pnf>F</pnf>Picard for taking the time in talking to me today. Please feel free to contact me if you have any additional questions.<br>Sincerely,<br><pnm>E</pnm>Bob Riker"; function proper_name_m($matches) { $titles = array( 'E' => 'Mr. ', 'S'