Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.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中的特定节点获取值_Php_Xml - Fatal编程技术网

Php从XML中的特定节点获取值

Php从XML中的特定节点获取值,php,xml,Php,Xml,我有一个xml响应,其中包含以下节点 $response = '<packet version="1.6.6.0"> <webspace> <del> <result> <status>ok</status> <filter-id>14</filter-id> <id>14</id> </

我有一个xml响应,其中包含以下节点

$response = '<packet version="1.6.6.0">
  <webspace>
    <del>
      <result>
        <status>ok</status>
        <filter-id>14</filter-id>
        <id>14</id>
      </result>
    </del>
  </webspace>
</packet>';
我收到错误
意外的T\u OBJECT\u运算符
,我认为它指示了
过滤器id
中的连字符“-”。我无法更改xml,因为它是API的响应。如何获取筛选器id

使用括号:

$dbres = simplexml_load_string($response);
$filterid = $dbres->webspace->result->{filter-id};
echo $filterid;
或投下它:

$dbres = simplexml_load_string($response);
$filterid = ((array) $dbres->webspace->result)['filter-id'];
echo $filterid;
或者-有点奇怪:

$dbres = simplexml_load_string(str_replace("filter-id", "filterid", $response));
$filterid = $dbres->webspace->result->filterid;
echo $filterid;
使用括号:

$dbres = simplexml_load_string($response);
$filterid = $dbres->webspace->result->{filter-id};
echo $filterid;
或投下它:

$dbres = simplexml_load_string($response);
$filterid = ((array) $dbres->webspace->result)['filter-id'];
echo $filterid;
或者-有点奇怪:

$dbres = simplexml_load_string(str_replace("filter-id", "filterid", $response));
$filterid = $dbres->webspace->result->filterid;
echo $filterid;
使用括号:

$dbres = simplexml_load_string($response);
$filterid = $dbres->webspace->result->{filter-id};
echo $filterid;
或投下它:

$dbres = simplexml_load_string($response);
$filterid = ((array) $dbres->webspace->result)['filter-id'];
echo $filterid;
或者-有点奇怪:

$dbres = simplexml_load_string(str_replace("filter-id", "filterid", $response));
$filterid = $dbres->webspace->result->filterid;
echo $filterid;
使用括号:

$dbres = simplexml_load_string($response);
$filterid = $dbres->webspace->result->{filter-id};
echo $filterid;
或投下它:

$dbres = simplexml_load_string($response);
$filterid = ((array) $dbres->webspace->result)['filter-id'];
echo $filterid;
或者-有点奇怪:

$dbres = simplexml_load_string(str_replace("filter-id", "filterid", $response));
$filterid = $dbres->webspace->result->filterid;
echo $filterid;
您可以尝试以下方法:

$dbres->webspace->result->{'filter-id'};
您可以尝试以下方法:

$dbres->webspace->result->{'filter-id'};
您可以尝试以下方法:

$dbres->webspace->result->{'filter-id'};
您可以尝试以下方法:

$dbres->webspace->result->{'filter-id'};


试试这个$dbres->webspace->result->{'filter-id'};让我试试看。。我马上给你发邮件。@Samir,你的解决方案对我有用。。但你并没有为此创造答案。如果您创建一个答案,我将很高兴接受它..答案补充。感谢这个$dbres->webspace->result->{'filter-id'};让我试试看。。我马上给你发邮件。@Samir,你的解决方案对我有用。。但你并没有为此创造答案。如果您创建一个答案,我将很高兴接受它..答案补充。感谢这个$dbres->webspace->result->{'filter-id'};让我试试看。。我马上给你发邮件。@Samir,你的解决方案对我有用。。但你并没有为此创造答案。如果您创建一个答案,我将很高兴接受它..答案补充。感谢这个$dbres->webspace->result->{'filter-id'};让我试试看。。我马上给你发邮件。@Samir,你的解决方案对我有用。。但你并没有为此创造答案。如果您创建一个答案,我将很高兴接受它..答案补充。谢谢你。。非常感谢。这正是我需要的。酷。。非常感谢。这正是我需要的。酷。。非常感谢。这正是我需要的。酷。。非常感谢。这正是我所需要的。@错觉:你可以投票支持我的答案,如果你愿意,可以将其标记为解决方案。我投票支持你的答案,因为我已经标记了Sameers的答案。@错觉:你可以投票支持我的答案,如果你愿意,可以将其标记为解决方案。我投票支持你的答案,因为我已经标记了Sameers的答案。@错觉:如果你愿意,你可以投票支持我的答案并将其标记为解决方案。我投票支持你的答案,因为我已经标记了Sameers的答案。@错觉:如果你愿意,你可以投票支持我的答案并将其标记为解决方案。我投票支持你的答案,因为我已经标记了Sameers的答案。