Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是一种无需 foreach 即可获得图像 src 的第一个值的方法?
$doc->loadHTML($description); foreach ($doc->getElementsByTagName('img') as $image) { echo $image->getAttribute('src'); }
这是行不通的$doc->getElementsByTagName('img')->item(0)->nodeValue);
$doc->getElementsByTagName('img')->item(0)->nodeValue);
这应该有效:
echo $doc->getElementsByTagName('img')->item(0)->getAttribute('src');