Simple usage example of the preg_replace_callback function in php, pregreplacecallback
This example describes the usage of the preg_replace_callback function in php. We will share this with you for your reference. The details are as follows:
Mixed preg_replace_callback (mixed pattern, callback, mixed subject [, int limit])
The behavior of this function is almost the same as that of preg_replace (), except that a replacement parameter is provided, but a callback function is specified. This function uses the matching array in the target string as the input parameter and returns the string to be replaced.
For example:
Preg_replace ($ skx, $ imsz2, $ neirong );
For example, there are multiple $ skx in $ neirong. I can get a different ID for each replacement.
Example:
<? Php $ str = 'this is a test for this string between des against this '; $ replace ='/this/X'; $ result = preg_replace_callback ($ replace, function ($ ms) {static $ I; $ I = $ I + 1; return "that ($ I)" ;}, $ str); echo $ result, "/n ";