使HTML文件中的变量在PHP文件中工作 [英] Making variable from HTML-file work in PHP-file

查看:42
本文介绍了使HTML文件中的变量在PHP文件中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个非常简单的文件.第一个是这样的HTML文件:

I have two rather simple files. The first is an HTML-file like this:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<html>
<body>

<form action="test.php" method="post">
Search for: <input type="text" name="search" />
<input type="submit" name="submit" value="Search" />
</form>

</body>
</html>

第二个文件是test.php,它看起来像这样:

The second file is test.php and it looks like this:

<?
       $filepath = "/usr/sbin";
       exec("ONE $search -command $filepath ");
       fopen($filepath, rw);
?>

我的问题是我想使用HTML表单中给出的参数搜索"作为PHP脚本中变量的值.一个是我制作的带有一个参数的搜索脚本,我希望它是"$ search".

My problem is that I want to use the argument "search" given in the HTML-form as value of variable in the PHP-script. ONE is a search script I made that takes one argument and I want it to be "$search".

可以这样做吗?如果可以,怎么办?

Could this be done and if so how?

非常感谢.

推荐答案

只需执行以下操作:

exec("ONE " . $_POST['search']. " -command $filepath ");

更新:
您在下一行中遇到另一个错误:

UPDATE:
You have another error, your following line:

fopen($filepath, rw);

应该是这样的:

fopen($filepath, "rw");

因为fopen()的第二个参数应作为字符串传递.

cause the second parameter to fopen() should be passed as a string.

更新2 :
如此看来,OP希望将命令的输出打印在页面上,因为您必须使用 passthru()代替exec(),就像这样:

UPDATE 2:
So as it seems, the OP want the output of the command to be printed on the page, for that you have to use passthru() instead of exec() , like so:

passthru("ONE " . $_POST['search']. " -command $filepath ");

这篇关于使HTML文件中的变量在PHP文件中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆