加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

PHP $argv仅限于Windows上的9个参数吗?

发布时间:2020-05-25 08:58:50 所属栏目:PHP 来源:互联网
导读:在Win7 32位上的 PHP 5.5.4 CLI中运行以下脚本 php -r print_r($argv); 1 2 3 4 5 6 7 8 9 10 11 12 13 14 我可以看到实际上只解析了8个参数: Array( [0] = - [1] = 1 [2] = 2 [3] = 3 [4] = 4 [5] = 5 [

在Win7 32位上的 PHP 5.5.4 CLI中运行以下脚本

php -r "print_r($argv);" 1 2 3 4 5 6 7 8 9 10 11 12 13 14

我可以看到实际上只解析了8个参数:

Array
(
    [0] => -
    [1] => 1
    [2] => 2
    [3] => 3
    [4] => 4
    [5] => 5
    [6] => 6
    [7] => 7
)

Windows或PHP是否将命令行参数的数量限制为8 /总计9?

更新:

在PHP 5.5.7的同一台PC上按预期工作 – >所以至少在Win7上这是一个特定于PHP的问题.

行为的变化取决于脚本是从php文件夹运行还是通过路径找到php. procmon跟踪似乎表明问题出在Windows上 – 甚至在加载PHP.exe映像之前 – 传递了不同数量的参数:

php.exe Process Start       SUCCESS Parent PID: 9088,Command line: "Program Filesphpphp"  -r "print_r($argv);" 1 2 3 4 5 6 7,Current directory: C:
php.exe Process Start       SUCCESS Parent PID: 9088,Command line: "program filesphpphp"  -r "print_r($argv);" 1 2 3 4 5 6 7 8 9 10 11 12 13 14,Command line: php  -r "print_r($argv);" 1 2 3 4 5 6 7 8 9 10 11 12 13 14,Current directory: C:Program Filesphp

如果不从路径中获取PHP,则所有参数似乎都可用.

在某些Windows环境中.要在Windows XP上获得9个以上的参数,您需要“移动”批处理文件中的参数.

我在XP上面的版本上找不到对此命令的任何引用,因此可能是因为Windows的更高版本会出现此问题.

关于PHP.NET的评论涵盖了它:http://www.php.net/manual/en/features.commandline.php#56846

To pass more than 9 arguments to your php-script on Windows,you can
use the ‘shift’-command in a batch file. After using ‘shift’,%1
becomes %0,%2 becomes %1 and so on – so you can fetch argument 10
etc.

Here’s an example – hopefully ready-to-use – batch file:

foo.bat:

@echo off

:init_arg
set args=

:get_arg
shift
if "%0"=="" goto :finish_arg
set args=%args% %0 goto :get_arg

:finish_arg

set php=C:pathtophp.exe
set ini=C:pathtophp.ini
%php% -c %ini%
foo.php %args%

Usage on commandline: foo -1 -2 -3 -4 -5 -6 -7 -8 -9 -foo -bar

A print_r($argv) will give you all of the passed arguments.

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读