2012-06-18 28 views
1

此代碼解析HTML內容,並返回一個div屬性

$html = file_get_html('http://runkeeper.com/user/'.RUNKEEPER_ID.'/activity/'); 
$link1 = $html->find('.activityMonth', 0); 

將返回第一個(FOO,0)使用簡單的HTML DOM的活動清單的元素。

下面是輸出($ LINK1的內容):我需要解析第一個div的 「鏈接」 屬性,獲取活動ID(95648619,在這種情況下)

<div class="activityMonth menuItem selected" link="/user/zzvimercm/activity/95648619"><div class="highlight"></div><div class="distanceUnit">km.</div><div class="distance">7.26</div> 
<div class="day"><img src="http://d2b4ufapzmnxpw.cloudfront.net/build/3694/static/kronos/images/icon-calendar-17.png" width="24" height="26" border="0" /></div> 
<div class="mainText">Running</div> 
</div> 

。我猜sscanf或簡單的HTML DOM本身可能會伎倆,但我迄今沒有取得成功。

任何提示?

在此先感謝

回答

0

例子:

// Get the "link" 
$link = $html->find('div[link]', 0)->link; 

// Explode the link, and get the last item 
$activity_id = end(explode('/', $link)); 
+0

偉大的作品,非常感謝。 – flapane