3v4l.org

run code in 300+ PHP versions simultaneously
<?php $torrent = 'd8:announce37:http://blender.waag.org:6969/announce13:creation datei1212070099e4:infod6:lengthi196898674e4:name30:big_buck_bunny_720p_stereo.ogg12:piece lengthi262144e6:pieces15040:DñÀsÑ45/'; $regex = "/(lengthi[0-9]+e)/i"; $sizes = array(); preg_replace_callback($regex, function($matches) use(&$sizes) { $sizes[] = substr($matches[2], 0, $matches[1]); }, $torrent); var_dump($sizes); // I want to get "262144", you can see this just before "pieces", top right
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Warning: Undefined array key 2 in /in/D9MQd on line 12 Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /in/D9MQd on line 12 Fatal error: Uncaught TypeError: substr(): Argument #3 ($length) must be of type ?int, string given in /in/D9MQd:12 Stack trace: #0 /in/D9MQd(12): substr('', 0, 'lengthi19689867...') #1 [internal function]: {closure}(Array) #2 /in/D9MQd(9): preg_replace_callback('/(lengthi[0-9]+...', Object(Closure), 'd8:announce37:h...') #3 {main} thrown in /in/D9MQd on line 12
Process exited with code 255.
Output for 8.1.0 - 8.1.28
Warning: Undefined array key 2 in /in/D9MQd on line 12 Deprecated: substr(): Passing null to parameter #1 ($string) of type string is deprecated in /in/D9MQd on line 12 Fatal error: Uncaught TypeError: substr(): Argument #3 ($length) must be of type ?int, string given in /in/D9MQd:12 Stack trace: #0 /in/D9MQd(12): substr('', 0, 'lengthi19689867...') #1 [internal function]: {closure}(Array) #2 /in/D9MQd(13): preg_replace_callback('/(lengthi[0-9]+...', Object(Closure), 'd8:announce37:h...') #3 {main} thrown in /in/D9MQd on line 12
Process exited with code 255.
Output for 8.0.0 - 8.0.30
Warning: Undefined array key 2 in /in/D9MQd on line 12 Fatal error: Uncaught TypeError: substr(): Argument #3 ($length) must be of type ?int, string given in /in/D9MQd:12 Stack trace: #0 /in/D9MQd(12): substr('', 0, 'lengthi19689867...') #1 [internal function]: {closure}(Array) #2 /in/D9MQd(13): preg_replace_callback('/(lengthi[0-9]+...', Object(Closure), 'd8:announce37:h...') #3 {main} thrown in /in/D9MQd on line 12
Process exited with code 255.
Output for 7.3.12 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
Notice: Undefined offset: 2 in /in/D9MQd on line 12 Warning: substr() expects parameter 3 to be int, string given in /in/D9MQd on line 12 Notice: Undefined offset: 2 in /in/D9MQd on line 12 Warning: substr() expects parameter 3 to be int, string given in /in/D9MQd on line 12 array(2) { [0]=> NULL [1]=> NULL }
Output for 7.3.32 - 7.3.33, 7.4.26
Warning: substr() expects parameter 3 to be int, string given in /in/D9MQd on line 12 Warning: substr() expects parameter 3 to be int, string given in /in/D9MQd on line 12 array(2) { [0]=> NULL [1]=> NULL }
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33
Notice: Undefined offset: 2 in /in/D9MQd on line 12 Warning: substr() expects parameter 3 to be integer, string given in /in/D9MQd on line 12 Notice: Undefined offset: 2 in /in/D9MQd on line 12 Warning: substr() expects parameter 3 to be integer, string given in /in/D9MQd on line 12 array(2) { [0]=> NULL [1]=> NULL }
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28
Notice: Undefined offset: 2 in /in/D9MQd on line 12 Warning: substr() expects parameter 3 to be long, string given in /in/D9MQd on line 12 Notice: Undefined offset: 2 in /in/D9MQd on line 12 Warning: substr() expects parameter 3 to be long, string given in /in/D9MQd on line 12 array(2) { [0]=> NULL [1]=> NULL }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/D9MQd on line 9
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/D9MQd on line 9
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/D9MQd on line 9
Process exited with code 255.

preferences:
270.69 ms | 401 KiB | 355 Q