简体   繁体   English

如何使用正则表达式查找所有图像标签

[英]How to find all image tags using Regular Expressions

I need to find all the image html tags that are included in a page using PHP regular expressions 我需要使用PHP正则表达式查找页面中包含的所有图像HTML标记

Example

<img src="images/image.jpg" />

My code 我的密码

preg_match('/<img src=\"images\/.*/',$tags,$matches);

The strange thing is it only finds the first occurence, not the rest of the tags in the page 奇怪的是,它只找到第一个匹配项,而不是页面中的其余标签

Use preg_match_all . 使用preg_match_all preg_match only finds the first occurence, while preg_match_all finds all occurrences of the pattern. preg_match仅查找第一次出现,而preg_match_all查找该模式的所有出现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM