php - How to get only the first result from getElementsByTagName? -


this question has answer here:

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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -