dooid3005 2016-02-26 20:35
浏览 35
已采纳

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

hello i want show paragraph with image from database. but i want delete inline style width image.

example :

   <?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; ?>

i want delete width image in inline style.

this code result i want like this

   <?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; ?>
  • 写回答

2条回答 默认 最新

  • dqnf28092 2016-02-26 20:45
    关注

    here ya go - using regular expressions

    <?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);
    ?>
    

    showing regex is matching https://regex101.com/r/xE8gX7/1

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?