ds211107 2012-10-26 03:44
浏览 213
已采纳

如何使用notepad ++运行带参数的php文件

How to run php file with parameter using notepad++

test.php

<?php 
    /* ------- 
        test.php
    ------- */
    if(!isset($_GET['file'])){
        exit;
    }
    $code=file_get_contents($_GET['file']);
    echo $code;

?>

demo_file.php -----$(FULL_CURRENT_PATH)

contents:

hello world


cd "D:\PHPnow-1.5.6\htdocs\zc_default\my_debug_fw"<br>
"d:\PHPnow-1.5.6\php-5.2.14-Win32\php.exe" "test.php" [what here?]

how to send "demo_file.php" as $_GET['file'] to test.php ?

The console finally should output:...... hello world

  • 写回答

2条回答 默认 最新

  • doumu5934 2012-10-26 04:30
    关注

    When utilizing PHP from the command line the arguments aren't passed in as part of the $_GET superglobal. They're passed in as part of the $_SERVER - superglobal where $_SERVER['argc'] is the number of arguments and $_SERVER['argv'] is an array of the argument values. $_SERVER['argv'][0] is the name of the php script and $_SERVER['argv'][1] would be the first argument.

        if($_SERVER['argc'] < 2){
            exit("Usage: php test.php <file>");
        }
    
        $code = file_get_contents($_SERVER['argv'][1]);
    

    Per your example above...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块
  • ¥15 nhanes加权logistic回归,svyglm函数