gpt4 book ai didi

php - 删除内联样式php中的样式宽度图像

转载 作者:太空宇宙 更新时间:2023-11-04 10:42:59 25 4
gpt4 key购买 nike

你好,我想用数据库中的图像显示段落。但我想删除内联样式宽度图像。

例子:

   <?php $prg = "hello this is paragragph and this is image 1 
<img src='https://www.google.co.id/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png' style='width:150px;heigh:150px'>
this is text and this is image 2
<img src='http://www.bing.com/az/hprichbg/rb/HumpbackWhaleReunion_ROW11050338497_1366x768.jpg' style='width:150px;heigh:150px' ></p>";

echo $prg; ?>

我想删除内联样式的宽度图像。

我想要这样的代码结果

   <?php $prg = "hello this is paragragph and this is image 1 
<img src='https://www.google.co.id/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png' style='heigh:150px'>
this is text and this is image 2
<img src='http://www.bing.com/az/hprichbg/rb/HumpbackWhaleReunion_ROW11050338497_1366x768.jpg' style='heigh:150px' ></p>";

echo $prg; ?>

最佳答案

开始吧 - 使用正则表达式

<?php
$prg = "hello this is paragragph and this is image 1
<img src='https://www.google.co.id/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png' style='width:150px;heigh:150px'>
this is text and this is image 2
<img src='http://www.bing.com/az/hprichbg/rb/HumpbackWhaleReunion_ROW11050338497_1366x768.jpg' style='width:150px;heigh:150px' ></p>";

echo preg_replace("/width:[0-9]+[a-z]{2};?/i",'',$prg);
?>

显示正则表达式匹配 https://regex101.com/r/xE8gX7/1

关于php - 删除内联样式php中的样式宽度图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35665711/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com