【发布时间】:2011-10-20 04:06:37
【问题描述】:
我制作了一个主要由 POST 请求提供支持的 PHP 脚本,它显示了一个类似于命令提示符的 HTML 表单,如何模拟文本添加?我的意思是这样的(Mac OS X 终端):
这是我的代码:
HTML:
<!DOCTYPE html>
<html lang="es">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Terminal</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<?php
include("co.php");
echo $prompt;
?>
</body>
</html>
PHP:
<?php
$command=$_POST['command'];
echo "<!DOCTYPE html>
<html lang=\"es\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
<title>Terminal</title>
<link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\" />
</head>";
$prompt .= "<header><p>Today is: ".date("M d")." of ".date("o")."</p><p class=\"command\"><label><form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\" autocomplete=OFF>www@".$_SERVER['SERVER_NAME'].":~$><input name=\"command\" type=\"text\" id=\"command\" size=\"40\" maxlength=\"500\" autofocus></label></form></p></header>";
$commandexp = explode(" ", $command);
if($commandexp[0] === "echo") {
$prompt .= $prompt.$commandexp[1].$prompt;
echo $prompt;
} else {
echo "command not found";
}
?>
提前致谢:)
【问题讨论】:
-
你不能只使用 PHP + HTML,你也必须使用 JavaScript。
-
这听起来不像是 PHP 问题。您想要的是能够附加到显示的输出,可能在每次接受用户输入之后。如果是这样,您需要一个 Javascript 解决方法来模拟终端效果。
-
关于如何做到这一点的任何线索?我真的想在最后一个输出中附加一个提示