@ 2015-12-21T07:34:43Z <?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);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
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.5.24 - 5.5.30 , 5.6.8 - 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 . preferences:dark mode live preview
167.62 ms | 1395 KiB | 25 Q