将文本文件中的一行添加到php中的文本框中


Add line from a textfile to a textbox in php

我想在我的html代码中添加特定行中的特定文本到文本框中。

我通过使用

从文本文件(这是一个BASH脚本)中获得该行:
<?php 
    $myFile = "C:'dat300backups'script.txt";
        $lines = file($myFile);//file in to an array
        echo $lines[13];
?>

然后我想要我从:

得到的文本
echo $lines[13];

插入文本框:

IP Subnet: <input type="text" name="ipsubnet" value="I want the line here"><br>

完整代码如下:

    <html>
    <head>
    <title>Rate Limiter</title>
    </head>
    <body>
    <?php 
    $myFile = "C:'dat300backups'script.txt";
    $lines = file($myFile);//file in to an array
    echo $lines[13];
    echo("<br>");
    echo $lines[14];
    echo("<br>");
    echo $lines[15];
    echo("<br>");   
    echo $lines[16];
    echo("<br>");
    echo $lines[17];
    echo("<br>");
    echo $lines[18];
    echo("<br>");
    echo $lines[19];
    echo("<br>");
    echo $lines[20];
    echo("<br>");
    echo $lines[21];
    echo("<br>");
    echo("<br>");

    ?>
    <form>
    IP Subnet: <input type="text" name="ipsubnet" value=""><br>
    IP From: <input type="text" name="ipfrom"><br>
    IP To: <input type="text" name="ipto"><br>
    WAN: <input type="text" name="wan"><br>
    LAN: <input type="text" name="lan"><br>
    Traffic Control Path: <input type="text" name="tcpath"><br>
    PacketLimit: <input type="text" name="packetlimit"><br>
    Download Rate: <input type="text" name="drate"> kbit/s<br>
    Upload Rate: <input type="text" name="urate"> kbit/s<br>
    </form>
    <form name="input" action="html_form_action.asp" method="get">
    Password: <input type="password" name="pwd">
    <input type="submit" value="Submit">
    </form>


    </body>
</html>
IP Subnet: <input type="text" name="ipsubnet" value="<?php echo $lines[13]; ?>">

您可以通过以下方式将PHP变量作为值传递到html代码中。不要忘记将文件保存为。php扩展名,下面的代码应该是html格式。

这是你的短标签(不是一个好的做法):

IP Subnet: <input type="text" name="ipsubnet" value="<?=$lines[13]; ?>">

这是"经典"标签:

IP Subnet: <input type="text" name="ipsubnet" value="<?php echo $lines[13]; ?>">

整理一下你的代码:

<?php 
    $myFile = "C:'dat300backups'script.txt";
    $lines = file($myFile);//file in to an array
    for ($i = 13, $i <= 21; $i++) {
        echo "<input type='"text'" name='"ipsubnet'" value='"" . $lines[$i] . "'"><br>'n";
    }
    echo("<br>");

?>