Hi there i am using the code to get the adress of all images from url adress. I want to ask how i can get only the first result not all matches?
Here is the code that i am 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 as $tag) {
echo $tag->getAttribute('src');
}
?>
So please tell me how i can get only one result - the first!
Thanks in advance.
$xpath->evaluate('string(//img[1]/@src)')
$doc->getElementsByTagName('img')->item(0)->getAttribute('src');
Note that the dupe is an exact dupe of this one and not the one linked in my comment.