Home >Backend Development >PHP Tutorial >preg_replace_callback_array() function in PHP 7
The Preg_replace_callback_array() function represents a regular expression in PHP 7 and replaces the use of callback functions. This function returns a string or array of strings to match a set of regular expressions and replace them using a callback function.
preg_replace_callback_array(patterns, input, limit, count)
Demonstration
<html> <head> <title> PHP 7 Featuretutorialpoint:</title> </head> <body> <?php $subject = 'AaaaaaaBbbbCccc'; preg_replace_callback_array ( [ '~[a]+~i' => function ($match) { echo strlen($match[0]), ' number of "a" found', PHP_EOL; }, '~[b]+~i' => function ($match) { echo strlen($match[0]), ' number of "b" found', PHP_EOL; }, '~[c]+~i' => function ($match) { echo strlen($match[0]), ' number of "c" found', PHP_EOL; } ], $subject ); ?> </body> </html>
The output of the above program code is −
7 number of "a" found 4 number of "b" found 5 number of "c" found
The above is the detailed content of preg_replace_callback_array() function in PHP 7. For more information, please follow other related articles on the PHP Chinese website!