我有一个像以下一样的HTML代码块
<div class="searchDetailPanelRgt">
<p>
<span>ID: 10605814 | Jun 26, '12</span>
<br />
<a href="somelink" target="_blank">View on Map</a>
<a target='_blank' href='somelink' ></a>
</p>
</div>
我想在php中使用HTML DOM库来访问Jun 26,12
值。
$html->find(???)
答案 0 :(得分:0)
<?php
$html = <<<HTML
<div class="searchDetailPanelRgt">
<p>
<span>ID: 10605814 | Jun 26, '12</span>
<br />
<a href="somelink" target="_blank">View on Map</a>
<a target='_blank' href='somelink' ></a>
</p>
</div>
HTML;
$document = new DOMDocument();
$document->loadHTML($html);
$spans = $document->getElementsByTagName("span");
$the_first_span = $spans->item(0);
$the_first_spans_content = explode(" | ", $the_first_span->textContent);
echo $the_first_spans_content[1];