|
US PHP IDE : Introduction | Notepad++ | Install PHP | NppExec Config | PHP extensions | Run Menu | XDebug 1 | Debugging 1 | XDebug 2 | Debugging 2
|
|
|
Uniform Server Portable PHP IDE. |
NppExec plugin configuration
The NppExec plugin executes either a single command or list of commands. Commands are similar to that typed in at a command line prompt. Each list of commands may be stored with a unique name for later use.
This page covers commands required to run PHP CLI scripts and how to assign a shortcut key to run a stored list of commands.
If you have followed this tutorial from the beginning run the test script test.php by typing the following into the console window: C:\us_portable_ide\unicode\php\php.exe -n C:\us_notepad\php_scripts\test.php Result similar to this is displayed in the console window C:\us_portable_ide\unicode\php\php.exe -n C:\us_notepad\php_scripts\test.php C:\us_portable_ide\unicode\php\php.exe -n C:\us_notepad\php_scripts\test.php Process started >>> Test 123 <<< Process finished. ================ READY ================ |
Note: The NppExec plugin runs external programs directly and displays any output. Notice there is no need to open and display a file.
A console window does not allow copying and pasting using a mouse instead you use key combinations as follows.
Running scripts directly is a tedious process in particular you need to enter a full path for both the executable and script. To the rescue, Environment variables we use the following variables and substitute as appropriate.
To see these in action first open test.php in Notepad++
|
Enter the following commands in the console window:
Results as shown on right: |
echo $(FULL_CURRENT_PATH) C:\us_portable_ide\php_scripts\test.php ================ READY ================ echo $(NPP_DIRECTORY) C:\us_portable_ide\unicode ================ READY ================ |
Using the above Environment variables we can run the script currently displayed in Notepad++
Substitute the absolute paths as shown below:
Original code:
C:\us_portable_ide\unicode\php\php.exe -n C:\us_notepad\php_scripts\test.php
Becomes:
$(NPP_DIRECTORY)\php\php.exe -n $(FULL_CURRENT_PATH)
Type the above line into console window result as shown:
$(NPP_DIRECTORY)\php\php.exe -n $(FULL_CURRENT_PATH) C:\us_portable_ide\unicode\php\php.exe -n C:\us_portable_ide\php_scripts\test.php Process started >>> Test 123 <<< Process finished. ================ READY ================
We want to automate the process ideally if the script has changed we want to automatically save any changes. This is accomplished using the following command:
The following sequence of commands is required to run a PHP script currently displayed in Notepad++:
NPP_SAVE cls $(NPP_DIRECTORY)\php\php.exe -n $(FULL_CURRENT_PATH) |
- Save current file |
Typing above lines every time you want to run a script can be tiresome. NppExec allows you to save a list of commands and run them with a few key clicks. You can save a list of commands with a unique name allowing you to have several named command scripts.
Further automate the process by assigning a shortcut key to run a named command script.
The following shows how to create a command script, name it and assign a shortcut key. It allows you to run a PHP script currently displayed in Notepad++.
|
Open Execute Window 1 Open execute script window as follows:
|
|
|
|
|
You can save any number of command scripts the following shows how to select and run a script.
|
Run Command script
|
In order to assign a shortcut key a command script must first be assigned to a menu item. This menu item is then assigned to a shortcut key using the mapper.
Restart Notepad++ check a new menu item Run as PHP CLI You can click this item and run it. |
Final part is to assign a shortcut key to the command script run_php using the key mapper as follows:
|
Run Shortcut mapper
|
|
|
Shortcut pop-up window From this you can select various combination of keys.
Quick test: Press the right arrow key check it runs the displayed PHP script. |
Nppexec provides three Console Filters filter, replace and highlight.
The highlight filter is of particular interest. It scans console output for string matches and highlights that text.
Double clicking on highlighted text takes you to that line in a script.
For example this line is a reported error from a PHP script:
Fatal error: Call to undefined function phpinfo_zzz() in C:\us_portable_ide\php_scripts\test2.php on line 5
Setting a highlight mask with the following format
%ABSFILE% on line %LINE%
Will highlight lines that match.
|
Open filter window
Quick check
|
At this stage we have a working PHP CLI IDE it runs scripts, highlights errors and provides the ability to jump to that error line in the edit window.
Currently it is configured to run with no PHP extensions enabling these are covered on the next page.
This IDE allows you to run a displayed PHP script in one of three ways as follows: