在一个数组中处理多个PHP脚本(Process multiple PHP scripts in one array)

系统教程 行业动态 更新时间:2024-06-14 17:04:03
在一个数组中处理多个PHP脚本(Process multiple PHP scripts in one array)

我有多个PHP脚本来ping每个位置,我试图在一个页面上列出所有结果。

这是ping脚本:

<?php $host = "10.10.10.10"; //IP adress to ping $loc = ("HQ"); //Name of location $output = array(); echo("<b>$loc</b> <i>(IP: $host)</i> is "); exec("ping -n 1 $host 2>&1", $output); //print_r($output); //you can use print_r($output) to view the output result if (count($output) > 7) { $output = null; die ("<font color='green'><b>up</b></font>"); } else { $output = null; die ("<font color='red'><b>down</b></font>"); } ?>

所以,我有很多这个脚本的php文件,唯一的区别是host和loc 。 我试图将每个文件包含在一个新的php文件中,使用如下所示:

<?php include "file1.php"; include "file2.php"; include "file3.php"; ...and so on... ?>

但这只输出第一个文件的结果。

我怎么能以其他方式做到这一点?

谢谢!

I have multiple php scripts to ping each of our locations, and I'm trying to list all results on one page.

Here's the ping script:

<?php $host = "10.10.10.10"; //IP adress to ping $loc = ("HQ"); //Name of location $output = array(); echo("<b>$loc</b> <i>(IP: $host)</i> is "); exec("ping -n 1 $host 2>&1", $output); //print_r($output); //you can use print_r($output) to view the output result if (count($output) > 7) { $output = null; die ("<font color='green'><b>up</b></font>"); } else { $output = null; die ("<font color='red'><b>down</b></font>"); } ?>

So, I have many php files with this script, where the only difference is host and loc. I've tried to include each file in a new php file using include like this:

<?php include "file1.php"; include "file2.php"; include "file3.php"; ...and so on... ?>

But this only outputs the result of the first file.

How can I do this in any other way?

Thanks!

最满意答案

die()或其等效的exit()结束脚本。 只需将die()更改为echo如下所示:

if (count($output) > 7) { $output = null; echo "<font color='green'><b>up</b></font>"; } else { $output = null; echo "<font color='red'><b>down</b></font>"; }

die(), or its equivalent exit() ends the script. Simply change die() to echo as in:

if (count($output) > 7) { $output = null; echo "<font color='green'><b>up</b></font>"; } else { $output = null; echo "<font color='red'><b>down</b></font>"; }

更多推荐

本文发布于:2023-04-24 21:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/a27b1663ee74528a72cac20853b2f9c9.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   在一   脚本   组中   个数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!