如何通过从bash的参数PHP脚本? [英] How to pass parameters from bash to php script?
本文介绍了如何通过从bash的参数PHP脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经做了哪些运行PHP脚本一个bash脚本。它工作正常,无参数,但是当我添加参数(ID和URL),存在一些误区:
PHP德precated:评论开始以'#'是德$ P $的在/ etc / PHP5 / CLI / conf目录.D / mcrypt.ini pcated 1号线未知在线0
无法打开输入文件:/var/www/dev/dbinsert/script/automatisation.php? ID = 1
我运行在bash这样的PHP脚本:
PHP /var/www/dev/dbinsert/script/automatisation.php?id=19&url=http://bkjbezjnkelnkz.com
解决方案
称其为:
PHP /path/to/script/script.php - 'ID = 19安培; URL = HTTP://bkjbezjnkelnkz.com
此外,修改你的PHP脚本,以使用 parse_str():
parse_str($ ARGV [1]);
如果该指数 $ _ SERVER ['REMOTE_ADDR']
未设置。
更先进的处理可能需要 getopt的(),但 parse_str ()是一个quick'n'dirty方式得到它的工作。
I have done a a bash script which run php script. It works fine without parameters but when I add parameters (id and url), there are some errors:
PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf .d/mcrypt.ini on line 1 in Unknown on line 0
Could not open input file: /var/www/dev/dbinsert/script/automatisation.php? id=1
I run php script from the bash like this:
php /var/www/dev/dbinsert/script/automatisation.php?id=19&url=http://bkjbezjnkelnkz.com
解决方案
Call it as:
php /path/to/script/script.php -- 'id=19&url=http://bkjbezjnkelnkz.com'
Also, modify your PHP script to use parse_str():
parse_str($argv[1]);
If the index $_SERVER['REMOTE_ADDR']
isn't set.
More advanced handling may need getopt(), but parse_str() is a quick'n'dirty way to get it working.
这篇关于如何通过从bash的参数PHP脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文