note 129520 added to function.preg-replace-callback-array
| From: | claus@tondering.dk | Date: | Thu, 23 May 2024 09:01:08 +0000 |
| Subject: | note 129520 added to function.preg-replace-callback-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221337@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.137 (proxied: 176.20.63.107)
----
Manual Page -- https://php.net/manual/en/function.preg-replace-callback-array.php
Edit -- https://main.php.net/note/edit/129520
Del: integrated -- https://main.php.net/note/delete/129520/integrated
Del: useless -- https://main.php.net/note/delete/129520/useless
Del: bad code -- https://main.php.net/note/delete/129520/bad+code
Del: spam -- https://main.php.net/note/delete/129520/spam
Del: non-english -- https://main.php.net/note/delete/129520/non-english
Del: in docs -- https://main.php.net/note/delete/129520/in+docs
Del: other reasons-- https://main.php.net/note/delete/129520
Reject -- https://main.php.net/note/reject/129520
Search -- https://main.php.net/manage/user-notes.php