2017-06-16 233 views
0

我使用php執行服務器命令以從服務器檢索日誌數據,只需在php中使用以下語法執行該命令即可。將shell輸出轉換爲html表格

<?php 
    $result = shell_exec("$cmd"); 
    echo "<pre>$result</pre>"; 
?> 

上面的查詢返回非結構化表格格式的輸出,我需要將其轉換爲結構化的HTML表格並顯示在網頁上。

我已經保存在CSV文件上面的命令輸出,並使用下面的JavaScript函數格式化結果以HTML表格

<script type="text/javascript"> 
    $.get('path/upload.csv', function(data) { 
    var build = '<table border="1" cellpadding="2" cellspacing="0" style="border-collapse: collapse" width="100%">\n'; 
    //var rows = data.split("\n"); 
    //rows.forEach(function getvalues(thisRow) { 
    var head = data.split("\n"); 
    for(var i=2;i<3;i++){ 
    build += "<tr><th>" + head[i].replace("first seen", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;seen") + "</th></tr>"; 
    //build += "<tr>"; 
      //var col = data.split("\n"); 
      for(var i=3;i<head.length;i++){ 
      build += "<tr><td>" + head[i].split("\n") + "</td></tr>"; 
      }    
    } 
    build += "</table>"; 
     $('#wrap').append(build); 
    }); 
</script> 

以上行格式腳本返回結果,我需要把它拆分成多列

my needs

+1

好吧,向我們展示您需要構建的數據。 – FMashiro

回答

0

您需要解析每行數據並添加適當的html表標記。