API2_query CPANEL电子邮件列表输出格式 - xmlapi

时间:2014-09-18 11:18:14

标签: php email cpanel

我使用了以下代码 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”:{ “结果”:1}, “数据”:[{ “修改时间”:1411037171, “diskquota”: “无限制”, “_ diskused”:“54

我希望输出在表格中。谁能建议 我怎么能这样做

1 个答案:

答案 0 :(得分:0)

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

首先将jason解码为Array

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>";