php - How to get only the first result from getElementsByTagName? -
this question has answer here:
- php domdocument, require first item only 2 answers
hi there using code adress of images url adress. want ask how can first result not matches?
here code using:
<?php $url="http://grabo.bg/relaks-v-pamporovo-0gk5b"; $html = file_get_contents($url); $doc = new domdocument(); @$doc->loadhtml($html); $tags = $doc->getelementsbytagname('img'); foreach ($tags $tag) { echo $tag->getattribute('src'); } ?>
so please tell me how can 1 result - first!
thanks in advance.
$tags
domnodelist
object created domdocument
's getelementsbytagname
method. can access first element returned domnodelist::item ( int $index )
.
for code do: $tags->item(0);
Comments
Post a Comment