1-31 2,127 views
代码
<?php
$html = <<<str
<html>
<head>
<title>123</title>
</head>
<body>
<img src="http://1.jpg" alt="">
<img src="http://2.jpg" alt="">
<img src="http://3.jpg" alt="">
<img src="http://4.jpg" alt="">
<img src="http://5.jpg" alt="">
</body>
</html>
str;
//读取字符串
$doc = new \DOMDocument();
$doc->loadHTML($html);
$xpath = new \DOMXPath($doc);
//解析src
$imgs = $xpath->query('//img/@src');
dump($imgs);
foreach ($imgs as $v) {
dump($v);
}