2012-08-26 59 views
0

我試圖提取鏈接的href屬性作爲字符串。使用simplexml_load_string提取屬性

<a href="http://example.com" target="_blank" class="someclass">Read More</a> 

我用下面的讀取提取物的屬性:

$link = simplexml_load_string($ad['meta_value']); 
$order['logo'] = $logo['href']->asXML(); 

非但沒有http://example.com我越來越href="http://example.com"的。除了使用str_replace()有沒有辦法將屬性提取爲字符串?

+0

什麼'substr'? –

回答

0

款待@attributes爲對象,並轉換爲字符串:

$link = simplexml_load_string($ad['meta_value']); 
echo (string) $link->attributes()->href;