Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用HTML链接打印PHP数组内容?_Php_Html - Fatal编程技术网

如何使用HTML链接打印PHP数组内容?

如何使用HTML链接打印PHP数组内容?,php,html,Php,Html,我似乎找不到解决我具体需要的办法。我有以下资料: <?php $hostname = shell_exec('hostname'); $manufacturer = `dmidecode -s system-manufacturer | tail -1`; $model = `dmidecode -s system-product-name | tail -1`; $product = `dmidecode | grep SKU | cut -d: -f2`; $serialno = `d

我似乎找不到解决我具体需要的办法。我有以下资料:

<?php
$hostname = shell_exec('hostname');
$manufacturer = `dmidecode -s system-manufacturer | tail -1`;
$model = `dmidecode -s system-product-name | tail -1`;
$product = `dmidecode | grep SKU | cut -d: -f2`;
$serialno = `dmidecode -s system-serial-number | tail -1`;
$iloipaddr = `ipmitool lan print | grep 'IP Address  ' | cut -d\: -f2 | sed 's/ //'`;
$sftwrlist = `rpm -qa | sort`;
?>

<p><b><u><big><?php echo $hostname;?></big></u></b><br/ >
<b>Manufacturer: </b><?php echo $manufacturer;?><br/ >
<b>Model: </b><?php echo $model;?><br/ >
<b>Serial Number: </b><?php echo $serialno;?><br/ >
<b>Product Number:</b><?php echo $product;?><br/ ><p/ >
<p><a href="http://<?php echo$iloipaddr;?>">ILO link: You must be on the same private subnet for this link to work.</a><p/ >
<b><u>Installed software</u></b>
<pre><?php echo print_r($sftwrlist);?></pre>
function newWindow() {
  var w = window.open();
  var html = $("pre").html();

    $(w.document.body).html(html);
}

$('a').click(function(e){
    e.preventDefault();
    newWindow();
})


制造商:
型号:
序列号:
产品编号:

安装的软件
当你把浏览器指向这台机器时,你会得到一些关于它的基本信息,一个指向它的iLO的链接和一个格式良好的已安装软件列表。作为代码的最后一行,我希望创建一个链接,单击该链接可以显示$sftwrlist数组,每行显示一个包。我尝试过使用href的各种方法,但我不确定href是否是合适的方法。提前感谢。

我通常使用:


p.S.$sftwrlist未被shell_exec?

如果您想将从
rpm-qa | sort
返回的每个项目的链接应用到一个数组中,然后将链接应用到该数组,您可以在输出时或之前执行以下操作

<?php
$array = explode(PHP_EOL, $sftwrlist);

array_walk($array, function(&$value, $key) {
    preg_match('/-\d/', $value, $match, PREG_OFFSET_CAPTURE);

    $offset = !empty($match) ? $match[0][1] : strlen($value);

    $value = [
        'name' => substr($value, 0, $offset), 
        'version' => trim(substr($value, $offset), '-')
    ];
});

print_r($array);

谢谢你的回复。当我等待大家的建议时,我确实想出了一个方法。尽管它确实需要另一个php脚本,而不是一个脚本中的整个代码。新脚本:


安装的软件
在原稿中:



所以,至少我可以把它添加到我的新技巧包中,但我现在将注意力转向这里的建议,看看我还能学到什么。当我找到自己的方法时,任何其他建议都肯定是受欢迎的。

try只是使用
shell\u exec()
执行的第一个命令,或者它们应该是相同的吗?如果只是解析,请提供
rpm-qa | sort
的输出,并展示您希望链接的方式。@Nigel:shell_exec和back ticks正在我尝试不同的方法来获得我想要/需要的东西。因为我是PHP和HTML新手,所以我只是想了解一下什么是有效的,什么是无效的,以供将来参考。一旦我得到我需要的东西,我可能会清理这个脚本并使它更同质化。编程是学习新东西的持续练习,所以尝试总是很好。意识到我实际上没有回答这个问题,所以更新了它。因为我处于学习模式,我正在试验shell_exec和back ticks。我很可能会在我真正明白我要做的事情之后把一切都搞定。
<?php
$sftwrlist = `rpm -qa | sort`;

$array = explode(PHP_EOL, $sftwrlist);

$rpmlink = 'http://www.rpm-find.net/linux/rpm2html/search.php?query=';

array_walk($array, function(&$value, $key) use ($rpmlink) {
    $value = sprintf('<a href="%s%s">%s</a>', $rpmlink, $value, $value);
});

print_r($array);
Array
(
    [0] => <a href="http://www.rpm-find.net/linux/rpm2html/search.php?query=filesystem-2.4.0-1">filesystem-2.4.0-1</a>
    [1] => <a href="http://www.rpm-find.net/linux/rpm2html/search.php?query=comps-extras-11.1-1.1">comps-extras-11.1-1.1</a>
    [2] => <a href="http://www.rpm-find.net/linux/rpm2html/search.php?query=gnome-mime-data-2.4.2-3.1">gnome-mime-data-2.4.2-3.1</a>
    [3] => <a href="http://www.rpm-find.net/linux/rpm2html/search.php?query=glibc-2.5-12">glibc-2.5-12</a>
    [4] => <a href="http://www.rpm-find.net/linux/rpm2html/search.php?query=atk-1.12.2-1.fc6">atk-1.12.2-1.fc6</a>
    [5] => <a href="http://www.rpm-find.net/linux/rpm2html/search.php?query=libICE-1.0.1-2.1">libICE-1.0.1-2.1</a>
    [6] => <a href="http://www.rpm-find.net/linux/rpm2html/search.php?query=db4-4.3.29-9.fc6">db4-4.3.29-9.fc6</a>
    [7] => <a href="http://www.rpm-find.net/linux/rpm2html/search.php?query=elfutils-libelf-0.125-3.el5">elfutils-libelf-0.125-3.el5</a>
    [8] => <a href="http://www.rpm-find.net/linux/rpm2html/search.php?query=ncurses-5.5-24.20060715">ncurses-5.5-24.20060715</a>
    [9] => <a href="http://www.rpm-find.net/linux/rpm2html/search.php?query=libsepol-1.15.2-1.el5">libsepol-1.15.2-1.el5</a>
    [10] => <a href="http://www.rpm-find.net/linux/rpm2html/search.php?query=libcap-1.10-26">libcap-1.10-26</a>
)
<?php
$array = explode(PHP_EOL, $sftwrlist);

array_walk($array, function(&$value, $key) {
    preg_match('/-\d/', $value, $match, PREG_OFFSET_CAPTURE);

    $offset = !empty($match) ? $match[0][1] : strlen($value);

    $value = [
        'name' => substr($value, 0, $offset), 
        'version' => trim(substr($value, $offset), '-')
    ];
});

print_r($array);
Array
(
    [0] => Array
        (
            [name] => filesystem
            [version] => 2.4.0-1
        )

    [1] => Array
        (
            [name] => comps-extras
            [version] => 11.1-1.1
        )

    [2] => Array
        (
            [name] => gnome-mime-data
            [version] => 2.4.2-3.1
        )

    [3] => Array
        (
            [name] => glibc
            [version] => 2.5-12
        )

    [4] => Array
        (
            [name] => atk
            [version] => 1.12.2-1.fc6
        )

    [5] => Array
        (
            [name] => libICE
            [version] => 1.0.1-2.1
        )

    [6] => Array
        (
            [name] => db4
            [version] => 4.3.29-9.fc6
        )

    [7] => Array
        (
            [name] => elfutils-libelf
            [version] => 0.125-3.el5
        )

    [8] => Array
        (
            [name] => ncurses
            [version] => 5.5-24.20060715
        )

    [9] => Array
        (
            [name] => libsepol
            [version] => 1.15.2-1.el5
        )

    [10] => Array
        (
            [name] => libcap
            [version] => 1.10-26
        )
)
<?php
$sftwrlist = `rpm -qa | sort`;
?>

<b><u>Installed software</u></b>
<pre><?php echo print_r($sftwrlist);?></pre>
<p><a href="sftwr.php">Installed Software</a><p/ >