{dede:field.body runphp=yes}
global $cfg_basehost;
$str = @me;
$search = '/(]+>)/is';
$search1 = '/(]+>)/is';
$search2 = '#()#i';
$search3 = '#()#i';
$content = preg_replace($search, '$1$3', $str);
$content = preg_replace($search1, '$1$3', $content);
$content = preg_replace($search2, '$1$2', $content);
$content = preg_replace($search3, '$1$2', $content);
@me = $content;
//@me = str_replace('/uploads/allimg/', $cfg_basehost.'/uploads/allimg/', $content);//手机版图片使用绝对路径
{/dede:field.body}
1. 使用正则表达式匹配所有 `
2. 同时,清除内联样式(`style`)中的 `width` 和 `height` 值。
3. 保留其他属性,确保图片的基本功能不受影响。
4. 最后一行代码(被注释掉的部分)可以用于将相对路径的图片转换为绝对路径,方便移动端加载。 通过这种方式,我们可以轻松实现手机端图片的优化显示,同时保持电脑端的正常浏览体验。这种方法不仅提高了网站的兼容性,还增强了用户体验,非常适合应用于自适应网站的设计中。希望这篇文章能帮助您更好地解决跨设备图片显示的问题!