Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我希望php代码从html表中查找href title和一些其他信息_Php_Html_Html Table_Domdocument - Fatal编程技术网

我希望php代码从html表中查找href title和一些其他信息

我希望php代码从html表中查找href title和一些其他信息,php,html,html-table,domdocument,Php,Html,Html Table,Domdocument,到目前为止,我创建了以下代码: <?php $url=" SOME HTML URL "; $html = file_get_contents($url); $doc = new DOMDocument(); @$doc->loadHTML($html); $tags = $doc->getElementsByTagName('a'); foreach ($tags as $tag) { echo $tag->getAttribute('href'); } ?&g

到目前为止,我创建了以下代码:

<?php
$url=" SOME HTML URL ";
$html = file_get_contents($url);
$doc = new DOMDocument();
@$doc->loadHTML($html);
$tags = $doc->getElementsByTagName('a');
foreach ($tags as $tag) {
    echo $tag->getAttribute('href');
}
?>

我有带表格的html页面,所以我想要标题和日期的链接。html代码示例:

<TR>
    <TD align="center" vAlign="top" bgColor="#ffffff" class="smalltext">3</TD>
    <TD  class="plaintext" ><a href="pdf/blahblah.pdf" target="_blank" class="link1style">THIS IS THE TITLE</a> </TD>
    <TD  align="center" class="plaintext" >THIS IS DATE</TD>
</TR>

3.
这是日期
对于链接,它对我来说很好,但我不知道如何使用其他链接


Tnx.

在您执行此操作的地方:

$tags = $doc->getElementsByTagName('a');
你正在找回所有的A标签。只有一个

如果你想得到文本“THIS IS DATE”,你不能通过查看标签来得到它,因为文本不在A标签内,而是在TD标签内

$tds = $doc->getElementsByTagName('td');
。。。将用于获取所有TD元素,或者您可以为要定位的元素分配一个ID,并使用
getElementById

但是,基本上,这些信息都是完整的,在提问之前,您绝对应该阅读这些信息。快乐阅读

再一次,这是:

(相关的)(相关的)