2012-10-26 48 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直接運行的代碼!