# php去除页面中图片的style、height、width属性

**URL:** <https://www.shiqidu.com/t/topic/389>\
**Category:** 开发调优\
**Tags:** PHP\
**Created:** [2018 年4 月 3 日 02:13 UTC](https://www.shiqidu.com/t/topic/389 "2018-04-03T02:13:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![Leon](https://www.shiqidu.com/user_avatar/www.shiqidu.com/leon/32/5_2.png) [@Leon](https://www.shiqidu.com/u/Leon)\
发布日期： [2018 年4 月 3 日 02:13 UTC](https://www.shiqidu.com/t/topic/389/1 "2018-04-03T02:13:22Z")

</div>

有时候在抓取的网页内容的图片需要剔除一些不必要的属性，可以使用下面的正则去除style、height、width属性

```php
$html = preg_replace( '/(<img.*?)(style=.+?[\'|"])|((width)=[\'"]+[0-9]+[\'"]+)|((height)=[\'"]+[0-9]+[\'"]+)/i', '$1' , $html);

```
