我想在特定行中将特定文本添加到html代码中的文本框中。
我通过使用:
从文本文件(这是一个BASH脚本)中获取该行<?php
$myFile = "C:\dat300backups\script.txt";
$lines = file($myFile);//file in to an array
echo $lines[13];
?>
然后我想要我得到的文字:
echo $lines[13];
插入到texbox中:
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>
答案 0 :(得分:0)
您可以通过以下方式将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]; ?>">
答案 1 :(得分:0)
IP Subnet: <input type="text" name="ipsubnet" value="<?php echo $lines[13]; ?>">
答案 2 :(得分:0)
只是为了清理你的代码:
<?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>");
?>