1

我正在尝试将链接的 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() 之外,还有没有办法将属性提取为字符串?

4

1 回答 1

1

视为@attributes对象并转换为字符串:

$link = simplexml_load_string($ad['meta_value']);
echo (string) $link->attributes()->href;
于 2012-08-26T02:37:06.880 回答