2017-06-16 235 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表标记。