我正在尝试获取的'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');
}
答案 0 :(得分:0)
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