【发布时间】:2012-05-10 18:35:04
【问题描述】:
我不知道 php 正则表达式我希望从我的 html 中提取所有图像标签 <img src="www.google.com/exampleimag.jpg"> 我如何使用 preg_match_all 来做到这一点
感谢 SO 社区为您提供宝贵的时间
我的情况是这样的,没有整个 html dom,而只是一个带有 img 标签的变量$text="this is a new text <img="sfdsfdimg/pfdg.fgh" > there is another iamh <img src="sfdsfdfsd.png"> hjkdhfsdfsfsdfsd kjdshfsd dummy text
【问题讨论】:
-
您只想要所有图片,不管它们的
src值是多少? -
不要使用正则表达式解析 HTML;阅读 DomDocument - php.net/domdocument
-
使用 PHP HTML 解析器而不是正则表达式。 HTML 和正则表达式不能很好地混合。
-
@JonathanSampson 当我的情况如上时,我是否也需要 domdocument
-
@spiderman 我刚刚测试了你的文字,发现图像很好。
标签: php regex preg-match-all