0

我有一个 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>

我想Jun 26,12在 php 中使用 HTML DOM 库访问该值。

$html->find(???)
4

1 回答 1

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];
于 2012-07-03T15:29:24.527 回答