5

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?

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
CLUEL3SS
  • 223
  • 1
  • 3
  • 10
  • 6
    Just a note, you may want to accept some of the 8 questions you asked. You most likely won't get an answer if you don't select an answer. – Steven Sep 24 '11 at 00:54
  • 3
    I don't think Notepad++ can do that. Is it so much of a hassle to keep it open in your browser and just press Refresh? – Ry- Sep 24 '11 at 01:00
  • 1
    Sorry, Im pretty new to this site, how do I accept the questions I asked? Just for future reference when I'm asking another question.. I appreciate the heads up btw, thank you! – CLUEL3SS Sep 24 '11 at 03:44
  • The title of this question should be something like "How to open current Notepad++ file in Firefox". Downvote – AlxVallejo Sep 26 '12 at 15:14

8 Answers8

12

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}");
A. Gneady
  • 121
  • 1
  • 3
  • That looks pretty cool, but since I'm not familiar with the XML file nor how to launch files from notepadd++, I'm still trying to figure out how to actually put it in action. – Expedito Jan 06 '13 at 11:58
2

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

?>
Jesperai
  • 31
  • 2
2

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

Eli Y
  • 877
  • 16
  • 41
  • That worked! Thank you! I remember toying around with the appdata folder awhile back but had no idea it was used for something like this.. Thanks you! – CLUEL3SS Sep 24 '11 at 03:45
  • firefox "$(FULL_CURRENT_PATH)" to firefox "http://127.0.0.1:8080/ $(FILE_NAME)" – CLUEL3SS Sep 24 '11 at 03:48
  • yeah because as i said npp does not have half path variable – Eli Y Sep 24 '11 at 03:53
2

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.

El Developer
  • 3,345
  • 1
  • 21
  • 40
Kevin Scharnhorst
  • 721
  • 1
  • 7
  • 14
0

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}"); 
?>
Paul92
  • 8,827
  • 1
  • 23
  • 37
0

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

0

If one is just looking to run HTML and/or PHP directly from Notepad++ in Chrome, or other, add:

<Command name="Launch in Chrome FOLDER" Ctrl="yes" Alt="yes" Shift="yes" Key="82">chrome &quot;http://localhost/FOLDER/$(FILE_NAME)&quot;</Command>

in Notepad++'s shortcuts.xml file (At least in Windows)

Change both instances of "FOLDER" to one's subfolder in the webserver's root folder. The root folder in XAMPP is htdocs. Of course, change "Chrome" to the browser one is desiring to open the file.

For instance, one of mine is:

<Command name="Launch in Chrome 7GENERALTEST" Ctrl="yes" Alt="yes" Shift="yes" Key="82">chrome &quot;http://localhost/7GENERALTEST/$(FILE_NAME)&quot;</Command>
    

"7GENERALTEST" the containing subfolder for my HTML and PHP files IN development.

One can then duplicate and modify the above for additional browsers and/or folders, say, Firefox, or the folder "7GENERALTEST2", etc.

Dharman
  • 30,962
  • 25
  • 85
  • 135
JayJay123
  • 315
  • 1
  • 5
  • 12
0

To fix this problem just have Notepad++ open to a redirect file on your webserver. For instance....

Line in shortcuts.xml:

<Command name="Launch in Chrome" Ctrl="yes" Alt="yes" Shift="yes" Key="88">
chrome http://localhost/redirect.php?path=$(FULL_CURRENT_PATH)</Command>

Now your Redirect.php file:

if (!empty($_GET['path'])) {

    $path = str_replace($_SERVER['DOCUMENT_ROOT'], '', $_GET['path']);
    $redir = 'http://localhost' . $path;
    header("Location:$redir");   
}

Now any page that you run from any directory on your webserver will automatically open like it should. & obviously you can place the redirect.php anywhere on your localhost webserver it doesn't have to be in your root "htdocs" folder if that bothers you. hide it in a config dir or something where you keep your db link file or your head/foot files, etc..

dynastoned
  • 61
  • 7