Простой HTML DOM получить атрибут из тега <div> - PullRequest
0 голосов
/ 18 марта 2019

Я пытаюсь получить атрибут 'tel', но не могу его получить.

<div class="horizontal-center" ng-class="classActive()" ng-click="clicked($event)" id="7076213" account-id="536423" user-id="651772" event-label="listing-detail" event-action="phone-number-viewed-in-sideways" tel="8503128272" action-type="DetailPhone">

Я пытался с этими кодами. 1.

foreach ($html1->find('div.horizontal-center') as $phone) {
 echo   $ilanlar['phone'] = $phone->{'tel'};
}

2

foreach ($html1->find('div.horizontal-center') as $phone) {
 echo   $ilanlar['phone'] = $phone->getattribute('tel');
}

1 Ответ

0 голосов
/ 18 марта 2019
include('simple_html_dom.php');


$html1 = str_get_html('<div class="horizontal-center" ng-class="classActive()" ng-click="clicked($event)" id="7076213" account-id="536423" user-id="651772" event-label="listing-detail" event-action="phone-number-viewed-in-sideways" tel="8503128272" action-type="DetailPhone">');

foreach ($html1->find('div.horizontal-center') as $phone) {
    echo $ilanlar['phone'] = $phone->{'tel'};
}

echo '<br>'; 

foreach ($html1->find('div.horizontal-center') as $phone) {
    echo $ilanlar['phone'] = $phone->getattribute('tel');
}

У меня отлично работает. Выход:

8503128272<br>8503128272
...