我正试图从这个获得src:
<a class="poster" href="#">
<img itemprop="image" id="upload_poster" alt="alt" title="title" class="shadow"
src="https://image.tmdb.org/t/p/w185/z99yU71wH7JBHZX4tQ3XzPG521M.jpg"/>
</a>
能帮到我吗? 我是这样的:
$doc = new DOMDocument();
$doc->loadHTML($url);
$xpath = new DOMXPath($doc);
$tags = $xpath->query('//img[@class="shadow"]');
foreach ($tags as $tag) {
$tag->getAttribute('src');
}
//Guardo todo en un array
$data = array('moviedb' => $tag, 'msg' => 'success');
我不想要回声,我需要将数据保存在数组中。
此返回:[对象] [对象]
答案 0 :(得分:1)
在循环中,您需要包含将填充数组的数据:
foreach ($tags as $tag) {
$src = $tag->getAttribute('src');
$data[] = array('moviedb' => $src, 'msg' => 'success');
}
结果如下:
Array
(
[0] => Array
(
[moviedb] => https://image.tmdb.org/t/p/w185/z99yU71wH7JBHZX4tQ3XzPG521M.jpg
[msg] => success
)
)