简体   繁体   English

如何在PHP中编写Shell脚本命令并将其链接到下拉菜单

[英]How to write shell script command in PHP and link it to dropdown menu

I have a shell scrip command for displaying the output on a web page. 我有一个shell scrip命令,用于在网页上显示输出。

$output =  shell_exec("cd DSSAT46; ./dscsm046 CSCER046 A KSAS8101.WHX  2>&1");

$output=str_replace(" "," ",$output);

$lines = explode("\n", $output);


echo '<pre>';


echo'<table class="fixtable">';

for ($i = 21; $i < sizeof($lines); $i++)
 {
    echo '<tr>';
    $columns = explode("\t", $lines[$i]);
    foreach ($columns as $data) {
        echo '<td>'.$data.'</td>';
    }
    echo '</tr>';
}
echo '</table>';
echo '</pre>';

?> 

I have a drop down menu with values , lets say wheat,sugarcane,paddy. 我有一个带有值的下拉菜单,比方说小麦,蔗糖,水稻。

<form method="POST" action ="name above php file">

<select name="crop">
              <option value="wheat">Wheat</option>
              <option value="sugarcane">Sugarcane</a>
              <option value="paddy">Paddy</a>
        </select> 
</form>

How do I make the shell script command generic so that the "KSAS8101.WHX" changes to something else whenever I select another value from dropdown menu. 如何使Shell脚本命令具有通用性,以便每当我从下拉菜单中选择另一个值时,“ KSAS8101.WHX”都会更改为其他内容。

For instance if I select option sugarcane then only the value of "KSAS8101.WHX" should change to "UFGA8504.PPX" and the entire command should remain the same. 例如,如果我选择选项甘蔗,那么只有“ KSAS8101.WHX”的值应更改为“ UFGA8504.PPX”,并且整个命令应保持不变。

This is simple, compare POST value: 这很简单,比较POST值:

if ($_POST['crop'] == "wheat"){
    $options =  "KSAS8101.WHX";
} elseif($_POST['crop'] == "sugarcane") {
    $options =  "UFGA8504.PPX";
} elseif($_POST['crop'] == "paddy") {
    $options =  "UFGA8504.PPX";
}

$output =  shell_exec("cd DSSAT46; ./dscsm046 CSCER046 A $options  2>&1");

$output=str_replace(" ","&nbsp;",$output);

$lines = explode("\n", $output);


echo '<pre>';


echo'<table class="fixtable">';

for ($i = 21; $i < sizeof($lines); $i++)
{
    echo '<tr>';
    $columns = explode("\t", $lines[$i]);
    foreach ($columns as $data) {
        echo '<td>'.$data.'</td>';
    }
    echo '</tr>';
}
echo '</table>';
echo '</pre>';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM