假设我有一些这样的XML
<channel>
<item>
<title>This is title 1</title>
</item>
</channel>
下面的代码实现了我想要的功能,它将标题作为字符串输出
$xml = simplexml_load_string($xmlstring);
echo $xml->channel->item->title;
这是我的问题.下面的代码在该上下文中没有将标题视为字符串,因此我最终在数组中使用了一个SimpleXML对象,而不是字符串.
$foo = array( $xml->channel->item->title );
我就是这样绕过它的
$foo = array( sprintf("%s",$xml->channel->item->title) );
但这看起来很难看.
What's the best way to force a SimpleXML object to a string, regardless of context?