2016-10-08 3 views
0

ich versucht habe, Daten aus einer XML-Antwort zu extrahieren, die wie folgt aussehen:Extrahieren von Daten aus API-Antwort Problem

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 
     ) 

) 

Dies ist nur ein Teil der Antwort ist, wie es war zu groß, zu kleben, was ich so habe weit ist:

// 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 ist es, was die Antwort hält, wie es gerade jetzt ist, ist es den Druck der ersten Domain nur X-mal, auch wenn es um die Seite gedruckt ist die Domains wie folgt aussehen: camnevdomains.â €

alle Tipps würden auf die beste Weise, um diese Antwort zu behandeln geschätzt werden.

+0

Sie verwenden 'str_replace' für ein Array und nicht nur für einen String und dann nur, um den Wert wiederzugeben - Sie sollten' $ value ["domain"] 'verarbeiten – RamRaider

Antwort

0

Sie wahrscheinlich in dieser Richtung versuchen könnte - eine Zeichenkonvertierung Funktion wie mb_convert_encoding die Zeichenfolge zu konvertieren, um UTF-8

$keep = array(
    "ff8v77.com", 
    "dolphinroboticpoolcleaner.info" 
); 
$badchars='​'; 

$data = $addons['data']; 

foreach($data as $index => $arr){ 
    if(is_array($arr) && array_key_exists('domain', $arr)){ 

     $domain = $arr['domain']; 
     $domain = stripslashes(trim(mb_convert_encoding($domain, 'HTML-ENTITIES', 'UTF-8'))); 

     if(in_array($domain, $keep)){ 
      $keep[]=$domain; 
     } 
    } 
} 

auch einen Versuch wert ist sicherzustellen, dass Ihr HTML die richtigen Meta-Tags hat

<meta charset='utf-8' /> 

or, the older notation 

<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />