在一个数组中处理多个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>"; }更多推荐
发布评论