2012-10-26 45 views
2

如何使用记事本来运行参数PHP文件++如何使用记事本++

test.php的

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

?> 

demo_file.php运行php文件,参数--- - $(FULL_CURRENT_PATH)

项内容:

的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?] 

如何发送“demo_file.php”$_GET['file']test.php的

控制台最后应该输出:...... hello world

回答

0

当命令行参数不传递为$ _GET超全局的一部分使用PHP。它们作为$ _SERVER的一部分传入 - superglobal,其中$ _SERVER ['argc']是参数的数量,$ _SERVER ['argv']是参数值的数组。 $ _SERVER ['argv'] [0]是php脚本的名字,$ _SERVER ['argv'] [1]是第一个参数。

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

    $code = file_get_contents($_SERVER['argv'][1]); 

每你上面的例子......

+0

太棒了,谢谢 – linjuming

0

关闭记事本后++,去%APPDATA%/Notepad++和开放shortcuts.xml文件在记事本中。在附加下面的行。

<Command name="Launch Server" Ctrl="yes" Alt="yes" Shift="no" Key="90">chrome &quot;http://localhost/index.php?file=$(FULL_CURRENT_PATH)&quot;</Command>

现在更改默认的index.php在htdocs目录的内容

<?php 
    if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) 
    { $uri = 'https://'; } 

    else 
    { $uri = 'http://'; } 
    $uri .= $_SERVER['HTTP_HOST']; 

    if(isset($_GET['file'])) 
    { 
     $root = $_SERVER['DOCUMENT_ROOT']; 
     $file = str_replace('\\', '/', $_GET['file']); 
     $file = str_replace($root, '', $file); 

     header("Location: http://localhost{$file}"); 
    } 
    else 
    { 
     header('Location: '.$uri.'/xampp/'); 
     //header('Location: '.$uri.'/yourproject/'); 
    } 
    exit; 
?> 
Something is wrong with the XAMPP installation :-(

现在运行XAMPP并单击Notepad++>Run>Launch Server或使用快捷键CTRL+ALT+Z直接运行的代码!