Configuring Notepad++ to run php on localhost?

大兔子大兔子 提交于 2019-11-30 21:31:56

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

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

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

so i think it's impossible

but just keep the page open and refresh after editing

Here's a quick and dirty fix to run php files even if they are in subdirectories inside your document root. In 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>

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

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

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

header("Location: http://localhost{$file}");
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:

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

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

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.

Since I test in multiple browsers, I modified all of the pertinent rows in 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:

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

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

?>
محمد طه

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}"); 
?>

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..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!