编写PHP以在网页上运行Python脚本

时间:2018-12-14 18:16:59

标签: php html

我有一个python气泡排序脚本,希望使用PHP在网页上运行。我采用了一个执行类似操作的PHP脚本,并试图对其进行修改以使其达到目的。我的python脚本bubbleSort.py接受两个变量,排序大小(Ns)和重复(R)。该脚本的标题是lab42.php

<?php
    header('Access-Control-Allow-Origin: *');
    session_start();
    require_once("config.php");
    $sSize = $_GET["sSize"];
    $sRep = $_GET["sRep"];
    print "Size($Size) Rep($Rep) \n";
    echo "<pre>";
    echo exec("python/bubbleSort.py ".$sSize." ".$sRep." ".SERVER." ".USER." ".PASSWORD." ".DATABASE." 2>&1", $output);
    var_dump ($output);
    echo "</pre>"; 
    /*
    $command= escapeshellcmd("python/bubbleSort.py ".$Size." ".$Rep." 2>&1");
    $output = shell_exec($command);
//  exec("python/bubbleSort.py ".$Size." ".$Rep." 2>&1", $output);
    echo $output;
    */
?>

但是,当我尝试在网页上运行它时,它不执行气泡排序。相反,它只是重新加载页面,并将变量添加到地址的末尾。这是网页资源的一部分,我尝试调用PHP脚本。

<h2 class="h2" >Lab4.2 Online</h2>
          <div class="card" style="width: 100%;">
            <div class="card-header d-flex justify-content-between align-items-center">
                    World of Sorts
            </div>
            <div class="card-body"> 
                <ul class="list-group">
                    <span class="btn btn-primary btn-small" data-toggle="collapse" href="#bubbleSort">
                            Magic of Bubble Sorting
                    </span>
                    <div id="bubbleSort" class="collapse">
                        <form class="form-signin">
                            <div class="row">
                                <input type="number" name="sSize" min="1000" max="9000" class="col form-control" placeholder="Sort size(N) [1000-9000]" required>
                                <input type="number" name="sRep" min="1" max="5" class="col form-control" placeholder="Repeting [1-5]" required>
                            </div>
                            <button id="lab42" class="btn btn-small btn-primary btn-block mt-2">
                                Run
                            </button>
                        </form>
                        <hr>

0 个答案:

没有答案