宽度不定的图片
$str = '<p><br></p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/ai/2173">
<img src="https://img.php.cn/upload/ai_manual/000/000/000/175680367887724.png" alt="吉卜力风格图片在线生成">
</a>
<div class="aritcle_card_info">
<a href="/ai/2173">吉卜力风格图片在线生成</a>
<p>将图片转换为吉卜力艺术风格的作品</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="吉卜力风格图片在线生成">
<span>121</span>
</div>
</div>
<a href="/ai/2173" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="吉卜力风格图片在线生成">
</a>
</div>
<img style="max-width:90%" src="http://xxxx/uploads/details/142163431741415.jpg" alt="正则问题 将图片宽度替换为100%" ><img style="max-width:90%" src="http://xxxx/uploads/details/14216343172321.jpg" alt="正则问题 将图片宽度替换为100%" ><p><br></p>';$str = '<p><br></p><img style="max-width:90%" src="http://xxxx/uploads/details/142163431741415.jpg" alt="正则问题 将图片宽度替换为100%" ><img style="max-width:90%" src="http://xxxx/uploads/details/14216343172321.jpg" alt="正则问题 将图片宽度替换为100%" ><p><br></p>';
$str = '<p><br></p><img style="max-width:90%" src="http://xxxx/uploads/details/142163431741415.jpg" alt="正则问题 将图片宽度替换为100%" ><img style="max-width:90%" src="http://xxxx/uploads/details/14216343172321.jpg" alt="正则问题 将图片宽度替换为100%" ><p><br></p>';echo preg_replace('/(?<=style="width:).+?px;/i', '100%', $str);
echo preg_replace('/(?<=
楼上 好像只能替换第一张图片的宽度,后面的无效
@xuzuning 怎么加上img限制
你测试了没有啊? 代码贴出来看看。
楼上 好像只能替换第一张图片的宽度,后面的无效
$str = '




';//echo preg_replace('/(?<=style="width:).+?px;/i', '100%', $str);echo preg_replace('/(?<=
这样呢
echo preg_replace('/(?<=
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号