I'm trying to get href
attribute (url) and tag name from HTML using DOMDocument.
I have the following code, but I listing parameters together:
$searchNodeA = $dom->getElementsByTagName('li');
$searchNodeHref = $dom->getElementsByTagName('a');
foreach($searchNodeA as $searchNode)
{
$url = $searchNode->getAttribute('href');
$acko = $searchNode->getElementsByTagName('a');
$nazev = $acko->item(0)->nodeValue;
echo "$nazev<br />";
}/**/
foreach($searchNodeHref as $searchNode)
{
$url = $searchNode->getAttribute('href');
echo "$url<br />";
}/**/
How do we suddenly announcing results?
$url - $nazev
Use Xpath:
Select any
li
element//li
Any
a
element inside ali
element ...//li//a
... with a
href
attribute//li//a[@href]
Load, evaluate and iterate:
Output: