dongmi5177 2016-10-08 06:45
浏览 49

从API响应问题中提取数据

I have been trying to extract data from an xml response which looks like:

Array
(
    [apiversion] => 2
    [data] => Array
        (
            [0] => Array
                (
                    [basedir] => public_html/camnevbritishsweets.co.uk
                    [dir] => /home/paydayci/public_html/camnevbritishsweets.co.uk
                    [domain] => camnevbritishsweets.co.uk
                    [domainkey] => camnevbritishsweets_paydaycic2013.co.uk
                    [fullsubdomain] => camnevbritishsweets.paydaycic2013.co.uk
                    [reldir] => home:public_html/camnevbritishsweets.co.uk
                    [rootdomain] => paydaycic2013.co.uk
                    [status] => not redirected
                    [subdomain] => camnevbritishsweets
                )

            [1] => Array
                (
                    [basedir] => public_html/camnevdomains.info
                    [dir] => /home/paydayci/public_html/camnevdomains.info
                    [domain] => camnevdomains.info
                    [domainkey] => camnevdomains_paydaycic2013.co.uk
                    [fullsubdomain] => camnevdomains.paydaycic2013.co.uk
                    [reldir] => home:public_html/camnevdomains.info
                    [rootdomain] => paydaycic2013.co.uk
                    [status] => not redirected
                    [subdomain] => camnevdomains
                )

            [2] => Array
                (
                    [basedir] => public_html/cossacksoft.com
                    [dir] => /home/paydayci/public_html/cossacksoft.com
                    [domain] => cossacksoft.com
                    [domainkey] => cossacksoft.com_paydaycic2013.co.uk
                    [fullsubdomain] => cossacksoft.com.paydaycic2013.co.uk
                    [reldir] => home:public_html/cossacksoft.com
                    [rootdomain] => paydaycic2013.co.uk
                    [status] => not redirected
                    [subdomain] => cossacksoft.com
                )

            [3] => Array
                (
                    [basedir] => public_html/dog-care-advisor.com
                    [dir] => /home/paydayci/public_html/dog-care-advisor.com
                    [domain] => dog-care-advisor.com
                    [domainkey] => dog-care-advisor.com_paydaycic2013.co.uk
                    [fullsubdomain] => dog-care-advisor.com.paydaycic2013.co.uk
                    [reldir] => home:public_html/dog-care-advisor.com
                    [rootdomain] => paydaycic2013.co.uk
                    [status] => not redirected
                    [subdomain] => dog-care-advisor.com
                )

            [4] => Array
                (
                    [basedir] => public_html/dolphinroboticpoolcleaner.info
                    [dir] => /home/paydayci/public_html/dolphinroboticpoolcleaner.info
                    [domain] => dolphinroboticpoolcleaner.info
                    [domainkey] => dolphinroboticpoolcleaner.info_paydaycic2013.co.uk
                    [fullsubdomain] => dolphinroboticpoolcleaner.info.paydaycic2013.co.uk
                    [reldir] => home:public_html/dolphinroboticpoolcleaner.info
                    [rootdomain] => paydaycic2013.co.uk
                    [status] => not redirected
                    [subdomain] => dolphinroboticpoolcleaner.info
                )

            [5] => Array
                (
                    [basedir] => public_html/ff666fffff.com
                    [dir] => /home/paydayci/public_html/ff666fffff.com
                    [domain] => ff666fffff.com
                    [domainkey] => ff666fffff.com_paydaycic2013.co.uk
                    [fullsubdomain] => ff666fffff.com.paydaycic2013.co.uk
                    [reldir] => home:public_html/ff666fffff.com
                    [rootdomain] => paydaycic2013.co.uk
                    [status] => not redirected
                    [subdomain] => ff666fffff.com
                )

            [6] => Array
                (
                    [basedir] => public_html/ff8v.com
                    [dir] => /home/paydayci/public_html/ff8v.com
                    [domain] => ff8v.com
                    [domainkey] => ff8v.com_paydaycic2013.co.uk
                    [fullsubdomain] => ff8v.com.paydaycic2013.co.uk
                    [reldir] => home:public_html/ff8v.com
                    [rootdomain] => paydaycic2013.co.uk
                    [status] => not redirected
                    [subdomain] => ff8v.com
                )

            [7] => Array
                (
                    [basedir] => public_html/ff8v77.com
                    [dir] => /home/paydayci/public_html/ff8v77.com
                    [domain] => ff8v77.com
                    [domainkey] => ff8v77.com_paydaycic2013.co.uk
                    [fullsubdomain] => ff8v77.com.paydaycic2013.co.uk
                    [reldir] => home:public_html/ff8v77.com
                    [rootdomain] => paydaycic2013.co.uk
                    [status] => not redirected
                    [subdomain] => ff8v77.com
                )

        )

    [event] => Array
        (
            [result] => 1
        )

    [func] => listaddondomains
    [module] => Park
    [postevent] => Array
        (
            [result] => 1
        )

    [preevent] => Array
        (
            [result] => 1
        )

)

This is only part of the response as it was too big to paste, what i have so far is:

  // get addon domain list
  $addons = $xmlapi->listaddondomains($cpanelU);

  // debug which prints the response
  print "<pre>"; print_r($addons); print "</pre>";

  // keep these domains
  $keep = array("ff8v77.com","dolphinroboticpoolcleaner.info");

  // loop over the domains
  foreach ($addons['data'] as $value) 
  {
        //echo $value["domain"] . "<br />"; 
        echo str_replace('​', "", $keep);
        if (in_array(trim($value["domain"]), $keep)) 
        {
           echo 'IN Array > ' . $value["domain"] . "<br />";
        } else {
           echo 'NOT IN Array > ' . $value["domain"] . "<br />";
        }   
  }

$addons is what holds the response, as it is just now, it's printing the first domain only X times, also when it's printed to page the domains look like: camnevdomains.​info this symbol "​" is new to me i have never seen this before, so my $keep array is failing becuase this is added to the domain for some reason.

any tips would be appreciated on the best way to handle this reponse.

  • 写回答

2条回答 默认 最新

  • dqg63264 2016-10-08 06:51
    关注
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)