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) { var_dump($match); global $placeholder_image; return sprintf('<img'.$match[1].'src="%s" data-original="'.$match[2].'" class="lazy"'.$match[3].'><noscript><img'.$match[1].'src="'.$match[2].'"'.$match[3].'></noscript>', get_tumbail($match[2],$placeholder_image)); },$imgStr); var_dump($imgStr); $imgStr = preg_replace('#<img([^>]+?)src=[\'"]?([^\'"\s>]+)[\'"]?([^>]*)>#', sprintf('<img${1}src="%s" data-original="${2}" class="lazy"${3}><noscript><img${1}src="${2}"${3}></noscript>', get_tumbail($2,$placeholder_image)), $imgStr); var_dump($imgStr);
based on C1HOs
Output for 7.0.0 - 7.0.1
Parse error: syntax error, unexpected '2' (T_LNUMBER), expecting variable (T_VARIABLE) or '{' or '$' in /in/cfG5u on line 19
Process exited with code 255.
Output for 5.4.11 - 5.6.16
Parse error: syntax error, unexpected '2' (T_LNUMBER), expecting variable (T_VARIABLE) or '$' in /in/cfG5u on line 19
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in /in/cfG5u on line 19
Process exited with code 255.