配置 Notepad++ 以在本地主机上运行 php?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7536238/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:53:47  来源:igfitidea点击:

Configuring Notepad++ to run php on localhost?

phplocalhostnotepad++

提问by CLUEL3SS

I am trying to get the option Run->Launch With Firefox; to open the file I am currently viewing in Notepad++ at http://127.0.0.1:8080/currentfile.php, but instead it just opens to current file directory in Firefox.. I've tried to edit the shortcut xml file in the Notepad++ directory, I've shut Notepad++ down and edited the XML file with regular Notepad, and when I start Notepad++ back up it does not show the settings I entered.. How can I edit the settings to load localhost rather than the file directory in Firefox?

我正在尝试选择 Run->Launch With Firefox;打开我当前在 Notepad++ 中查看的文件http://127.0.0.1:8080/currentfile.php,但它只是在 Firefox 中打开到当前文件目录。文件与常规记事本,当我启动 Notepad++ 备份时,它不显示我输入的设置。如何编辑设置以加载本地主机而不是 Firefox 中的文件目录?

采纳答案by elibyy

well two things

好两件事

  1. you edited the wrong file , i'm guessing you are using windows vista/7 so real preferences files are in C:\Users\user\AppData\Roaming\Notepad++

  2. i don't think that notepad++ has a variable that contains only half of the address

  1. 你编辑了错误的文件,我猜你使用的是 windows vista/7 所以真正的首选项文件在 C:\Users\user\AppData\Roaming\Notepad++

  2. 我不认为记事本++有一个只包含一半地址的变量

meaning : the variable used now is $(FULL_CURRENT_PATH) == file:///C:/server/htdocs/pages/example.php

含义:现在使用的变量是 $(FULL_CURRENT_PATH) == file:///C:/server/htdocs/pages/example.php

so you don't have any variable that contains only this pages/example.php.

所以你没有任何只包含这个 pages/example.php 的变量。

so i think it's impossible

所以我认为这是不可能的

but just keep the page open and refresh after editing

但只需保持页面打开并在编辑后刷新

回答by A. Gneady

Here's a quick and dirty fix to run php files even if they are in subdirectories inside your document root. In shortcuts.xml:

这是运行 php 文件的快速而肮脏的修复程序,即使它们位于文档根目录中的子目录中。在快捷方式.xml中:

<Command name="Launch in Firefox" Ctrl="yes" Alt="yes" Shift="yes" Key="88">firefox &quot;http://localhost/redirect.php?file=$(FULL_CURRENT_PATH)&quot;</Command>

Then create the file "redirect.php" in your web server document root:

然后在您的 Web 服务器文档根目录中创建文件“redirect.php”:

<?php
$root = $_SERVER['DOCUMENT_ROOT'];

$file = str_replace('\', '/', $_GET['file']);
$file = str_replace($root, '', $file);

header("Location: http://localhost{$file}");

回答by Kevin Scharnhorst

If you save your PHP file directly into the www directory of WAMP (no subfolders), you can execute it by selecting the "Run..." command and pasting in this line:

如果将 PHP 文件直接保存到 WAMP 的 www 目录(无子文件夹),则可以通过选择“运行...”命令并粘贴到以下行中来执行它:

firefox.exe "http://localhost/$(FILE_NAME)"

It's not great, but it will help you debug in a jiffy.

这不是很好,但它会帮助您快速调试。

回答by Jesperai

I know this is an older question but:

我知道这是一个较旧的问题,但是:

A. Gneady's solution works well. However, it may require some modification on Windows so the DOCUMENT_ROOT is replaced before the slash directions are replaced. Otherwise, no replacement will be made and the $file will output the same as the original path and file name, except with the slashes reversed.

A. Gneady 的解决方案效果很好。但是,它可能需要在 Windows 上进行一些修改,因此在替换斜杠方向之前替换 DOCUMENT_ROOT。否则,将不会进行替换,$file 将输出与原始路径和文件名相同的内容,但斜杠已反转。

Since I test in multiple browsers, I modified all of the pertinent rows in C:\Users[username]\AppData\Roaming\Notepad++\shortcuts.xml:

由于我在多个浏览器中进行测试,因此我修改了 C:\Users[username]\AppData\Roaming\Notepad++\shortcuts.xml 中的所有相关行:

<Command name="Launch in Firefox" Ctrl="yes" Alt="yes" Shift="yes" Key="88">firefox &quot;http://localhost/redirect.php?file=$(FULL_CURRENT_PATH)&quot;</Command>
<Command name="Launch in IE" Ctrl="yes" Alt="yes" Shift="yes" Key="73">iexplore &quot;http://localhost/redirect.php?file=$(FULL_CURRENT_PATH)&quot;</Command>
<Command name="Launch in Chrome" Ctrl="yes" Alt="yes" Shift="yes" Key="82">chrome &quot;http://localhost/redirect.php?file=$(FULL_CURRENT_PATH)&quot;</Command>
<Command name="Launch in Safari" Ctrl="yes" Alt="yes" Shift="yes" Key="70">safari &quot;http://localhost/redirect.php?file=$(FULL_CURRENT_PATH)&quot;</Command>

Then create the "redirect.php" file in the web root directory as follows:

然后在web根目录下创建“redirect.php”文件如下:

<?php 
$root = $_SERVER['DOCUMENT_ROOT'];
$file = $_GET['file'];
$file = str_replace($root, '', $file);
$file = str_replace('\', '/', $file);

header("Location: http://localhost{$file}");

?>

回答by ???? ??

Was forgotten mark / after localhost

被遗忘的标记/在本地主机之后

<?php 
$root = $_SERVER['DOCUMENT_ROOT'];
$file = $_GET['file'];
$file = str_replace($root, '', $file);
$file = str_replace('\', '/', $file);

# Was forgotten mark /

header("Location: http://localhost/{$file}"); 
?>

回答by mechanic

this is the code which worked for me:

这是对我有用的代码:

<?php 
$root = $_SERVER['DOCUMENT_ROOT'];
$file = $_GET['file'];
$file = str_replace($root, '', $file);
$file = str_replace('\', '/', $file);
$file = str_replace('C:/wamp64/www/', '', $file); // Cause 'localhost' is equal to 'C:/wamp64/www/' in my case.
header("Location: http://localhost/{$file}"); 
?>

Thanks everybody..

谢谢大家..