domDocument를 사용하고 있습니다. 나는 가까이 있지만 마지막 조금을위한 도움이 필요합니다domDocument를 사용하여 src 요소 가져 오기
나는이 HTML을 아래에 단지 가지고있다. 행이 여러 개 있습니다. 나는 href를 얻으려고 노력하고있다.
지금까지 다음을 수행하고 있습니다. 테이블, tr 및 td를 얻을 수 있지만 거기에서 무엇을해야할지 확신하지 못합니다. 어떤 도움
감사
foreach ($dom->getElementsByTagName('table') as $tableitem) {
if ($tableitem->getAttribute('class') == 'tableStyle02'){
$rows = $tableitem->getElementsByTagName('tr');
foreach ($rows as $row){
$cols = $row->getElementsByTagName('td');
$hrefs = $cols->item(0)->getElementsByTagName('a');
}
}
}
HTML 코드 :
<table width="100%" border="0" cellspacing="0" cellpadding="2" class="tableStyle02">
<tr>
<td><span class="Name"><a href="bin.php?cid=703&size=0">
<strong>Conference Facility</strong></a></span></td>
<td align="center" nowrap>0.00</td>
<td align="center"> 0 </td>
<td align="center"> </td>
<td align="center"> 0 </td>
<td align="center"> 0 </td>
<td align="center"> 0 - 0 </td>
<td align="center"> Wired Internet, </td>
<td align="center"> </td>
</tr>
위대하고 새로운 기능입니다. 그래서 나는 조금 놀았고 또 하나의 질문이 있습니다. 내 테이블에 여러 href가있는 많은 행이 있습니다. $ href = $ xp-> evaluate ('string (// table [@ class = "tableStyle02"]/tr/td/a/@ href)'); 그러나 단지 첫번째를 얻었다. 나는 어떻게해야합니까? – randy
확실히, 그 변형에 대한 답을 편집했습니다. 이전에했던 것처럼 $ hrefs를 foreach 할 수도 있습니다. 그래서 두 방법 모두 잘 작동합니다. – hakre