宽度不定的图片
$str = '<p><br></p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/ai/2203">
<img src="https://img.php.cn/upload/ai_manual/000/000/000/175680008054255.png" alt="ChatX翻译">
</a>
<div class="aritcle_card_info">
<a href="/ai/2203">ChatX翻译</a>
<p>最实用、可靠的社交类实时翻译工具。 支持全球主流的20+款社交软件的聊天应用,全球200+语言随意切换。 让您彻底告别复制粘贴的翻译模式,与世界各地高效连接!</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="ChatX翻译">
<span>77</span>
</div>
</div>
<a href="/ai/2203" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="ChatX翻译">
</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号