我怎样才能得到所有的 <img>
带有 width >= 300
?
我的标记/代码:
$images = <<<END
<img src="/data/img/201108031_023" width="300" height="400" />
<img src="/data/img/201108031_026" width="250" height="300" />
<img src="/data/img/201108031_028" width="400" height="300" />
<img src="/data/img/201108031_032" width="500" height="400" />
...
END;
我的尝试:
preg_match_all("/<img(.*?) \/>/",$images,$matches);
print_r($matches);
最佳答案
为此使用正则表达式不是一个好主意。
这适用于您的特定示例,但它有许多问题,因为正则表达式无法正确解析 HTML:
"/<img[^>]*width=\"([3-9][0-9]{2}|[1-9][0-9]{3,})\"[^>]*>/"
在线查看它:ideone
我建议您改用 HTML 解析器。
相关
关于php - 如何在宽度 >= 300 的情况下对 IMG 进行正则表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8003101/