简体   繁体   English

解析CURL XML响应PHP

[英]Parse CURL XML response PHP

Please tell me how can i get $String value for key field name="Contact Tags (Raw)" Basically i need something like this: 请告诉我如何获取键字段名=“联系人标签(原始)”的 $ String值基本上我需要这样的东西:

$XML->result->contact->Group_Tag("Sequences and Tags")->field("Contact Tags (Raw)") $ XML->结果-> contact-> Group_Tag(“序列和标签”)-> field(“联系标签(原始)”)

This is result I got 这是我得到的结果

在此处输入图片说明

MY PHP CODE: 我的PHP代码:

<?php
$data = <<<STRING
<search>
    <equation>
    <field>E-Mail</field>
    <op>e</op>
    <value>anast@gmail.com</value>
    </equation>
</search>
STRING;

$data = urlencode(urlencode($data));

$appid = "xxxxxxxxxxxxxxxxxx";
$key = "xxxxxxxxxxxxxxxxxx";

$reqType = "search";
$postargs = "appid=".$appid."&key=".$key."&reqType=".$reqType."&data=".$data;
$request = "https://api.moon-ray.com/cdata.php";

$session = curl_init($request);
curl_setopt ($session, CURLOPT_POST, true);
curl_setopt ($session, CURLOPT_POSTFIELDS, $postargs);
curl_setopt ($session, CURLOPT_HEADER, false);
curl_setopt ($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
header("Content-Type: text/xml");
$decoded = iconv("UTF-8", "ISO-8859-1//TRANSLIT", $response);
echo $decoded;

You can try this 你可以试试这个

$string = '<result>
<contact id="90676">
<Group_Tag name="Sequences and Tags">
    <field name="Contact Tags (Raw)">
        test test
    </field>
</Group_Tag>
</contact>
</result>';

$xml = simplexml_load_string($string);

if($xml->contact->Group_Tag['name'] == 'Sequences and Tags'){
    if($xml->contact->Group_Tag->field['name'] == 'Contact Tags (Raw)'){
        echo $xml->contact->Group_Tag->field;
    }
}

Updated 更新

<?php
    $xml=simplexml_load_file("http://i.shn-host.ru/json/srch.php") or die("Error: Cannot create object");

    foreach ($xml->contact->Group_Tag as $Group_Tag) {
        if($Group_Tag['name'] == 'Sequences and Tags'){
            foreach ($Group_Tag as $field) {
                if($field['name'] == 'Contact Tags (Raw)'){
                    echo $field;
                }
            }
        }
    }
?> 

Result I got 结果我得到了

22*/ 96 / 72 / 77 / 78 / 79 / 82 / 105 / 121 / 136 / 146 / 209 / 246 / 259 / 260 / 262 / 264 / 281 /*282 22 * / 96/72 /78分之77/ 79 / 一百○五分之八十二 /136分之121/ 二百○九分之一百四十六 /259分之246/ 二百六十二分之二百六 /281分之264/ * 282

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM