Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用simplexml\u load\u字符串提取属性_Php - Fatal编程技术网

Php 使用simplexml\u load\u字符串提取属性

Php 使用simplexml\u load\u字符串提取属性,php,Php,我正在尝试将link的href属性提取为字符串 <a href="http://example.com" target="_blank" class="someclass">Read More</a> 而不是获取http://example.com我得到了href=”http://example.com“。除了使用str_replace()之外,还有什么方法可以将属性提取为字符串?将@attributes视为对象并转换为字符串: $link = simplexml_lo

我正在尝试将link的href属性提取为字符串

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

而不是获取
http://example.com
我得到了
href=”http://example.com“
。除了使用str_replace()之外,还有什么方法可以将属性提取为字符串?

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

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

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

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