Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.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中,如何仅从XML获取XML属性的简单文本?_Php_Xml_Attributes_Traversal - Fatal编程技术网

在PHP中,如何仅从XML获取XML属性的简单文本?

在PHP中,如何仅从XML获取XML属性的简单文本?,php,xml,attributes,traversal,Php,Xml,Attributes,Traversal,我有一个XML,它是从一篇cURL文章返回的: $output=<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <mtMessageRsp carrier="102" messageId="769f2e4f-56da-4865-988a-a9199c387a48"/> $result正在捕获返回,返回为: $result = { "@attributes" : { carrier : "1

我有一个XML,它是从一篇cURL文章返回的:

$output=<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<mtMessageRsp carrier="102" messageId="769f2e4f-56da-4865-988a-a9199c387a48"/>
$result正在捕获返回,返回为:

$result = { 
  "@attributes" :  { 
    carrier : "102",
    messageId : "8d691cbe-d188-42b1-9041-387666d39c6a"
  }
如何向下钻取messageId作为平面文本?当我使用此选项时:

$result['messageId']
我得到:

{ 
  "0" : "bf629ae9-c86a-486a-bfb0-704e16448ddf"
}
但我只想:

bf629ae9-c86a-486a-bfb0-704e16448ddf

在另一篇帖子中找到了答案:

$msgID = (string) $result['messageId'];
必须将simpleXML对象强制转换为字符串。
POST:

您还可以在PHP手册中找到Simplexml的详细介绍:这不是“hakre”标记的文章的副本。
$msgID = (string) $result['messageId'];