2017-09-21 26 views
2
<div class="username-info-area"> 
       <img src="https://image5.sahibinden.com/users/47/06/46/p200_profile_14470646_8126809.png" class="user-profile-photo" height="50" width="50" alt=""> 
       <h5>familya yapı Gayrimenkul Gyo ltd şti</h5> 
       </div> 

我想獲取h5數據。 我可以訪問div.username-info-area。HTML DOM解析器獲取內部h5數據

$items = $new_data->find('div.username-info-area', 0)->outertext; 
     echo $items . '<br>'; 

回答

3

運行foreach循環內的if條款,看看這個例子出來,例如:

下面的腳本將確保,如果有一個h5值將打印$div及其outertext

<?php 
foreach ($new_data->find('div[class=username-info-area]') as $div) 
{ 
    if($div->find('h5') !== '') 
    { 
     print_r($div->outertext); 
    } 
} 
?> 

或者你可以在未來foreach循環內部運行的另一個foreach循環,例如。

<?php 
foreach ($new_data->find('div[class=username-info-area]') as $div) 
{ 
    foreach($div->find('h5') as $h5) 
    { 
     print_r($h5->outertext); 
    } 
} 
?> 

我希望這可以幫到你。