【问题标题】:API2_query CPANEL Email listing output format - xmlapiAPI2_query CPANEL 电子邮件列表输出格式 - xmlapi
【发布时间】:2014-09-18 11:18:13
【问题描述】:

我使用了以下代码 PHP代码:

include '../xmlapi.php'; 

$ip = 'ip'; 
$root_pass = 'pwd'; 

$account = "acc"; 

$xmlapi = new xmlapi($ip); 
$xmlapi->password_auth($account,$root_pass); 
$xmlapi->set_output("json"); 
$xmlapi->set_port(2082); 
$xmlapi->set_debug(1); 
$output = $xmlapi->api2_query($account, "Email", "listpopswithdisk" ); 
print $output;  

输出在 这样的格式 {"cpanelresult":{"apiversion":2,"preevent":{"result":1},"data":[{"mtime":1411037171,"diskquota":"unlimited","_diskused":"54

我希望输出在表格中。任何人都可以建议 我该怎么做呢

【问题讨论】:

    标签: php email cpanel


    【解决方案1】:

    有两种方法可以做到这一点

    首先将 jason 解码为数组

    include '../xmlapi.php'; 
    
    $ip = 'ip'; 
    $root_pass = 'pwd'; 
    
    $account = "acc"; 
    
    $xmlapi = new xmlapi($ip); 
    $xmlapi->password_auth($account,$root_pass); 
    $xmlapi->set_output("json"); 
    $xmlapi->set_port(2082); 
    $xmlapi->set_debug(1); 
    $output = $xmlapi->api2_query($account, "Email", "listpopswithdisk" ); 
    $output = json_decode($output)
    print_r($output);  
    

    其次是在 Array 中而不是 jason 中获取输出

    include '../xmlapi.php'; 
    
    $ip = 'ip'; 
    $root_pass = 'pwd'; 
    
    $account = "acc"; 
    
    $xmlapi = new xmlapi($ip); 
    $xmlapi->password_auth($account,$root_pass); 
    $xmlapi->set_output("array"); 
    $xmlapi->set_port(2082); 
    $xmlapi->set_debug(1); 
    $output = $xmlapi->api2_query($account, "Email", "listpopswithdisk" ); 
    print $output;  
    

    现在您可以使用 foreach 循环从该数组中打印表格

    echo "<table>";
    foreach ($output as $key => $value){ 
          echo '<tr>';
          echo '<td>' . $key . '</td>';
          echo '<td>' . $value . '</td>';
          echo '</tr>';
     }
    echo "</table>";
    

    【讨论】:

    • 我犯了同样的愚蠢错误。谢谢你救了我。
    猜你喜欢
    • 1970-01-01
    • 2014-07-27
    • 2015-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-26
    相关资源
    最近更新 更多