我正在尝试将link的href属性提取为字符串。
<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 :(得分:1)
将@attributes
视为对象并转换为字符串:
$link = simplexml_load_string($ad['meta_value']);
echo (string) $link->attributes()->href;