3v4l.org

run code in 300+ PHP versions simultaneously
<?php function get_tumbail($imgSrc,$placeholder_image){ $imgPattern = "/(http\:\/\/ww\d+\.sinaimg\.cn\/)(\w+)(\/\S+\.(jpg|gif))/i"; $matches = null; $result = preg_match($imgPattern, $imgSrc, $matches); if (!$result) { return $placeholder_image; } return $matches[1] . 'thumbnail' . $matches[3]; } $placeholder_image = 'images/transparent.gif'; $imgStr = '<img src="http://ww2.sinaimg.cn/bmiddle/a3d444e3jw1ez79amvdi1j20l50s8gpl.jpg"/>'; $imgStr = preg_replace_callback('#<img([^>]+?)src=[\'"]?([^\'"\s>]+)[\'"]?([^>]*)>#',function($match,$placeholder_image) { var_dump($match); return sprintf('<img$match[1]src="%s" data-original="$match[2]" class="lazy"$match[3]><noscript><img${1}src="${2}"${3}></noscript>', get_tumbail($match[2],$placeholder_image)); },$imgStr); var_dump($imgStr);
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed and exactly 2 expected in /in/sttBf:13 Stack trace: #0 [internal function]: {closure}(Array) #1 /in/sttBf(13): preg_replace_callback('#<img([^>]+?)sr...', Object(Closure), '<img src="http:...') #2 {main} thrown in /in/sttBf on line 13
Process exited with code 255.
Output for 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Fatal error: Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed and exactly 2 expected in /in/sttBf:13 Stack trace: #0 [internal function]: {closure}(Array) #1 /in/sttBf(16): preg_replace_callback('#<img([^>]+?)sr...', Object(Closure), '<img src="http:...') #2 {main} thrown in /in/sttBf on line 13
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20
Warning: Missing argument 2 for {closure}() in /in/sttBf on line 13 array(4) { [0]=> string(79) "<img src="http://ww2.sinaimg.cn/bmiddle/a3d444e3jw1ez79amvdi1j20l50s8gpl.jpg"/>" [1]=> string(1) " " [2]=> string(66) "http://ww2.sinaimg.cn/bmiddle/a3d444e3jw1ez79amvdi1j20l50s8gpl.jpg" [3]=> string(1) "/" } Notice: Undefined variable: placeholder_image in /in/sttBf on line 15 string(180) "<img$match[1]src="http://ww2.sinaimg.cn/thumbnail/a3d444e3jw1ez79amvdi1j20l50s8gpl.jpg" data-original="$match[2]" class="lazy"$match[3]><noscript><img${1}src="${2}"${3}></noscript>"

preferences:
160.46 ms | 403 KiB | 197 Q