我想检索课程并src
使用正则表达式的图像标签。
的位置class
and src
可以在任何地方。
我能够得到src
from /<img[^>]* src="([^\"]+)"[^>]*>/i
<img width="100" height="100" src="/woocom.png" class="hello hel" alt="woo">
<img width="100" height="100" class="hello hel" src="/woocom.png" alt="woo">`
在这里尝试过在线正则表达式 https://regex101.com/r/jknSTx/2
因为有 PHP 标签。我不建议在这种情况下使用正则表达式。正则表达式是一把锤子,当你理解它时,你周围的一切看起来都像钉子。在 PHP 中我们有DOMDocument
该任务的类。例如下面:
$d = new DOMDocument();
$d->loadHTML('<img width="100" height="100" src="/woocom.png" class="hello hel" alt="woo">');
$images = $d->getElementsByTagName('img');
foreach ($images as $image) {
echo $image->getAttribute('src');
echo $image->getAttribute('class');
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)