为什么不PHP接受命令参数$ 1 [英] Why doesn't PHP accept command with argument $1

查看:166
本文介绍了为什么不PHP接受命令参数$ 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/12500129/making-variable-from-html-file-work-in-php-file\">Making在PHP文件的HTML文件的工作变

我有一个传递一个参数的PHP文件另一个文件(HTML文件)。它让我与回声检查,它抛回我在HTML文件中写道相同的参数,所以到目前为止,一切都很好。 PHP的文件看起来是这样的。

I have another file (HTML-file) that passes an argument to this PHP-file. It does so I have checked it with "echo" and it throws back the same argument I wrote in the HTML-file, so so far, so good. The PHP-file looks like this.

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

命令ONE,这是一个bash脚本我写的做一些里grep在文件中有一个参数,那就是$搜索,这在行为传递到这个PHP文件。如果我交流$搜索,以实际的单词搜索内容它就像一个魅力。为什么它不接受$搜索作为参数?它只是似乎忽略它,并抛回一个空白页,但如果我用搜索内容它给回我想要什么。

The command "ONE" which is a bash-script I wrote to do some "greps" in files takes one argument and that is "$search" which in deed is passed over to this PHP-file. And if I exchange "$search" to the actual word "searchword" it works like a charm. Why doesn't it accept "$search" as argument? It just seem to ignore it and throws back a blank page, but if I use "searchword" it gives back just what I want.

推荐答案

您在的fopen 语法错误(可能是抄写错误)。

You have a syntax error in fopen (probably a transcription error).

你的意思是使用 $ _ REQUEST ['搜索'] 而不仅仅是 $搜索?通过传递参数传递给这个PHP文件的HTML文件我假设你通过一个链接或某种异步请求的意思。如果是那样的话,你应该使用 escapeshellarg

Do you mean to use $_REQUEST['search'] as opposed to just $search? By "HTML-file that passes an argument to this PHP-file" I assume you mean via a link or asynchronous request of some kind. If that's the case, you should use escapeshellarg.

这篇关于为什么不PHP接受命令参数$ 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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