【问题标题】:convert shell output to html table将 shell 输出转换为 html 表
【发布时间】:2017-11-19 04:16:48
【问题描述】:

我正在使用 php 执行服务器命令以从服务器检索日志数据,只需使用以下语法在 php 中执行命令。

<?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>

以上脚本以行格式返回结果,我需要将其拆分为列

【问题讨论】:

  • 好吧,向我们展示您需要构建的数据。

标签: javascript php shell


【解决方案1】:

您需要解析每一行数据并添加适当的html表格标签。

【讨论】:

    猜你喜欢
    • 2011-01-03
    • 2019-02-25
    • 1970-01-01
    • 2016-08-17
    • 1970-01-01
    • 2014-03-27
    • 2017-12-31
    • 2015-07-29
    • 2017-08-03
    相关资源
    最近更新 更多