3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $subject = 'Aaaafaba Bbab'; $ret = preg_replace_callback( '~[a]+~i', function ($match) { echo strlen(match[0], ' matches for "a" found', PHP_EOL); }, $subject ); var_dump($ret); var_dump($subject); $ret = preg_replace_callback_array( [ '~[a]+~i' => function ($match) { echo strlen($match[0]), ' matches for "a" found', PHP_EOL; }, '~[b]+~i' => function ($match) { echo strlen($match[0]), ' matches for "b" found', PHP_EOL; } ], $subject ); var_dump($ret); var_dump($subject);
based on i9pdS
Output for 7.2.0
Warning: Use of undefined constant match - assumed 'match' (this will throw an Error in a future version of PHP) in /in/oUuKE on line 8 Warning: strlen() expects exactly 1 parameter, 3 given in /in/oUuKE on line 8 Warning: Use of undefined constant match - assumed 'match' (this will throw an Error in a future version of PHP) in /in/oUuKE on line 8 Warning: strlen() expects exactly 1 parameter, 3 given in /in/oUuKE on line 8 Warning: Use of undefined constant match - assumed 'match' (this will throw an Error in a future version of PHP) in /in/oUuKE on line 8 Warning: strlen() expects exactly 1 parameter, 3 given in /in/oUuKE on line 8 Warning: Use of undefined constant match - assumed 'match' (this will throw an Error in a future version of PHP) in /in/oUuKE on line 8 Warning: strlen() expects exactly 1 parameter, 3 given in /in/oUuKE on line 8 string(6) "fb Bbb" string(13) "Aaaafaba Bbab" 4 matches for "a" found 1 matches for "a" found 1 matches for "a" found 1 matches for "a" found 1 matches for "b" found 3 matches for "b" found string(2) "f " string(13) "Aaaafaba Bbab"
Output for 7.0.0 - 7.1.10
Notice: Use of undefined constant match - assumed 'match' in /in/oUuKE on line 8 Warning: strlen() expects exactly 1 parameter, 3 given in /in/oUuKE on line 8 Notice: Use of undefined constant match - assumed 'match' in /in/oUuKE on line 8 Warning: strlen() expects exactly 1 parameter, 3 given in /in/oUuKE on line 8 Notice: Use of undefined constant match - assumed 'match' in /in/oUuKE on line 8 Warning: strlen() expects exactly 1 parameter, 3 given in /in/oUuKE on line 8 Notice: Use of undefined constant match - assumed 'match' in /in/oUuKE on line 8 Warning: strlen() expects exactly 1 parameter, 3 given in /in/oUuKE on line 8 string(6) "fb Bbb" string(13) "Aaaafaba Bbab" 4 matches for "a" found 1 matches for "a" found 1 matches for "a" found 1 matches for "a" found 1 matches for "b" found 3 matches for "b" found string(2) "f " string(13) "Aaaafaba Bbab"
Output for 5.6.8 - 5.6.28
Notice: Use of undefined constant match - assumed 'match' in /in/oUuKE on line 8 Warning: strlen() expects exactly 1 parameter, 3 given in /in/oUuKE on line 8 Notice: Use of undefined constant match - assumed 'match' in /in/oUuKE on line 8 Warning: strlen() expects exactly 1 parameter, 3 given in /in/oUuKE on line 8 Notice: Use of undefined constant match - assumed 'match' in /in/oUuKE on line 8 Warning: strlen() expects exactly 1 parameter, 3 given in /in/oUuKE on line 8 Notice: Use of undefined constant match - assumed 'match' in /in/oUuKE on line 8 Warning: strlen() expects exactly 1 parameter, 3 given in /in/oUuKE on line 8 string(6) "fb Bbb" string(13) "Aaaafaba Bbab" Fatal error: Call to undefined function preg_replace_callback_array() in /in/oUuKE on line 16
Process exited with code 255.
Output for 5.3.18 - 5.5.35
Parse error: syntax error, unexpected '[' in /in/oUuKE on line 8
Process exited with code 255.