Voting

: zero minus zero?
(Example: nine)

The Note You're Voting On

claus at tondering dot dk
11 months ago
Note that the first replacement is applied to the whole string before the next replacement is applied.

For example:

<?php
$subject
= 'a b a b a b';

preg_replace_callback_array(
[
'/a/' => function ($match) {
echo
'"a" found', PHP_EOL;
},
'/b/' => function ($match) {
echo
'"b" found', PHP_EOL;
}
],
$subject
);

?>

will print

"a" found
"a" found
"a" found
"b" found
"b" found
"b" found

This means that you cannot use global variables to communicate information between the functions about what point in the string you have reached.

<< Back to user notes page

To Top