joshis Posted November 8, 2009 Share Posted November 8, 2009 Hi, How can I remove the height attribute from my img tag? Source string: <div ><a href='blah'><img width="7" height="9" alt="" src="images/img.jpg" /></a></div> I need the above content like this. <div ><a href='blah'><img width="7" alt="" src="images/img.jpg" /></a></div> Link to comment https://forums.phpfreaks.com/topic/180742-solved-remove-height-attribute-from-img-tag/ Share on other sites More sharing options...
Daniel0 Posted November 8, 2009 Share Posted November 8, 2009 Untested, but I think it'll work: preg_replace('#(<img.+?)height=(["\']?)\d*\2(.*?/?>)#i', '$1$3', $html); Link to comment https://forums.phpfreaks.com/topic/180742-solved-remove-height-attribute-from-img-tag/#findComment-953583 Share on other sites More sharing options...
joshis Posted November 8, 2009 Author Share Posted November 8, 2009 Thaks Daniel. It works.... Link to comment https://forums.phpfreaks.com/topic/180742-solved-remove-height-attribute-from-img-tag/#findComment-953585 Share on other sites More sharing options...
kronisk Posted November 8, 2009 Share Posted November 8, 2009 Hello PHP Freaks, I'm a new guy here . This question is related, so I'm posting it here: How can I remove ALL attributes but src from a img tag? Link to comment https://forums.phpfreaks.com/topic/180742-solved-remove-height-attribute-from-img-tag/#findComment-953717 Share on other sites More sharing options...
kronisk Posted November 8, 2009 Share Posted November 8, 2009 Hello PHP Freaks, I'm a new guy here . This question is related, so I'm posting it here: How can I remove ALL attributes but src from a img tag? Think I solved it myself: $html2 = preg_replace('#<img.+?src=[\'"]([^\'"]+)[\'"].*>#i', '<img src="$1">', $html2); Link to comment https://forums.phpfreaks.com/topic/180742-solved-remove-height-attribute-from-img-tag/#findComment-953724 Share on other sites More sharing options...
kronisk Posted November 8, 2009 Share Posted November 8, 2009 Here is a slight update to my previous post: $html2 = preg_replace('#<img.+?src=[\'"]([^\'"]+)[\'"].*?>#i', '<img src="$1">', $html2); Link to comment https://forums.phpfreaks.com/topic/180742-solved-remove-height-attribute-from-img-tag/#findComment-953739 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.