3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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);
based on u41cd
Output for 7.1.0 - 7.2.0
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.3.21 - 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>"