Php DOM脚本getElementsByID--链接

Php DOM脚本getElementsByID--链接,php,html,dom,Php,Html,Dom,我正在学习php和DOM。我有个问题。因此,我正在努力改进和理解以下内容。我有一些ID div的链接,我正在将事件附加到它们上: 在$hrefs的迭代中-请参考dingle href而不是列表: foreach ($href as $hrefs) { $link = $href->getAttribute('href'); //not $hrefs-> } 您的HTML标记非常糟糕——存在一些错误,这些错误无助于使用DOM <div id='article

我正在学习php和DOM。我有个问题。因此,我正在努力改进和理解以下内容。我有一些ID div的链接,我正在将事件附加到它们上:



在$hrefs的迭代中-请参考dingle href而不是列表:

foreach ($href as $hrefs) {
  $link = $href->getAttribute('href'); //not $hrefs->
}

您的HTML标记非常糟糕——存在一些错误,这些错误无助于使用DOM

<div  id='articleList1' >
    <div class="hotOne">
        <a class="" href="http://link1/index.html" >
            <span class="itemTitle">1 title</span>
            <img src="1.jpg" class="" alt="1" title="1" border="0" />
        </a>
    </div>
    <div class="hotThree">
        <ul>
            <li class="item item1 ">
                <a href="http://link2/index.html" title="2" >
                    <span class="itemTitle">2 title</span>
                    <img src="2.jpg" class="" alt="2" title="2" border="0" />
                    <p>2 tekst</p><!-- <~~~ error here previously -->
                </a>
            </li>
            <li class="item item2 ">
                <a href="http://link3.html" title="3" >
                    <span class="itemTitle">3 title</span>
                    <img src="3.jpg" class="" alt="3" title="3" border="0" />
                    <p>3 tekst</p><!-- <~~~ error here previously -->
                </a>
            </li>
        </ul><!-- missing -->
    </div>
</div><!-- missing -->


<?php
    $col=$dom->getElementsByTagName('a');
    foreach( $col as $node ){
        if( $node->nodeType===XML_ELEMENT_NODE && $node->hasAttribute('href') ){
            echo $node->getAttribute('href');
        }
    }
?>

hasAttribute('href')){ echo$node->getAttribute('href'); } } ?>
这只是php脚本的一部分。