If you’re looking for a free (donationware), open source text editor for PHP scripts, I recommend that you try jEdit. This is a mature, Java-based programmer’s text editor with an excellent set of core features, plus many more that can be added via "plugins."
Though jEdit is strongest at supporting Java, it does a pretty good job with PHP, and its core strengths work with any language. For PHP it doesn’t qualify as an IDE, or Integrated Development Environment, though it does share some features with the latter, including syntax highlighting and FTP. Some of the PHP IDE features that it lacks are debugging, and code completion.
In this article, we’ll look at some of jEdit’s general features, as well as its PHP-specific ones.
Download and Installation
Beware that a full setup requires a series of downloads, and that this process can take time. You’ll need a Java Runtime Environment (JRE), version 1.3 or higher, in order to use jEdit. If you don’t already have one installed, you can download it from Sun’s Java site.
Then, download jEdit. The latest version, as of this writing, is 4.2. Once you’ve downloaded the Java-based installer, double-click that .jar file and follow the installation steps. The default installation of jEdit doesn’t come with a jEdit icon, but you can get one from the jEdit site’s image store or from its community’s file store.
Program installation is usually simple, but if you have questions about installation, they will likely be answered by the jEdit installation FAQ.
When you first launch jEdit, jEdit Help will open, offering you the User Guide and an empty editing window. Beyond perusing the user guide, perhaps the next thing you’ll want to do is to download some plugins. jEdit has many plugins that extend its feature set. Though plugins are available from jEdit’s Plugin Central, generally, the easiest way to obtain and install them is to use jEdit’s built-in Plugin Manager.
To use the Manager, once your computer is online, go to Plugins | Plugin Manager in the empty editing window, and click on the Install tab. The list of plugins can be sorted by clicking on the column heading. Clicking on a plugin will bring up a description of the plugin. For starters, I recommend that you select the following plugins for installation:
Restart jEdit after installing these plugins.
Those who want spell check functionality have two choices: Spell Check, and Jazzy. Spell Check utilizes the Aspell spell checker, which supports many languages. To use Spell Check, first install Aspell (a Windows version is available). You’ll need to install a dictionary, too.
After the installation of those two items is complete, download the jEdit SpellCheck plugin, extract it, then place the .jar file in the same directory as the other plugin .jar files. You may have to search for them — they’re in the "jars" directory where your jEdit settings are kept — or the install might do it for you automatically. On Windows XP, for example, the .jar is correctly put in C:Documents and Settingsuser.jeditjars.
You can use Plugins | Plugin Options | Spell Check to point SpellCheck to the Aspell executable, and to select automatic markup for the PHP edit mode. Unfortunately, it appears that, at this time, Spell Check does not include the ability to add words to a user directory.
The other spell checker plugin, Jazzy, does include the ability to add words to a user dictionary. You can use the Plugin Manager to install Jazzy. You’ll also need to install a dictionary (only English is available: choose english_dic.zip) at the location of your choosing — perhaps in your .jedit folder. Use Plugins | Plugin Options | Jazzy to point to the location of the dictionary file eng_com.dic, and discard the other files.
You’ve now got all the files you need to use jEdit in a powerful way!
The next thing to do is to tweak the appearance of the editor.
To change the settings to suit your needs, go to Utilities | Global Options. I suggest that you don’t change the Status Bar settings for now, because by clicking on specific locations of the status bar (below the text area), you can quickly toggle particular handy settings, such as the wrapping of text. (I found that soft wrapping doesn’t seem to work correctly unless a monospaced font, such as Bitstream Vera Sans Mono, is used.)
You might also click on Plugins | Plugin Options | BufferTabs, and enable BufferTabs by default. Another plugin, Editor Scheme Selector, lets you change the colors of jEdit’s text area.
Right-clicking in the text area brings up a customizable menu. The default right-click menu has frequently-used picks.
If you spend some time exploring jEdit’s user’s guide, as well as the different menus, you’ll learn a lot. You can also learn from jEdit’s startup tips (Utilities | Global Options | jEdit | Appearance, Show tips on startup).
Search and Replace
jEdit has extensive search and replace capabilities. It can search a highlighted selection, the current buffer (i.e. the active file), all open buffers (files), and/or a directory and subdirectories, with or without using regular expressions in the search terms.
PHP Syntax Highlighting
The standard installation of jEdit includes syntax highlighting for over 130 file types, including PHP. I find this feature very handy while writing PHP code. The visual feedback of the colors helps reduce the number of syntax errors that might creep into my code.
Syntax highlighting in jEdit is controlled by XML files called "edit modes." These files, one for each file type, are kept in the "modes" directory of the jEdit installation. The edit mode for PHP is called php.xml.
Now, when I looked into this file and compared it to the current online documentation for PHP, I found that this edit mode file wasn’t quite up-to-date. I created a revised version and uploaded it to the jEdit community site, from which you can obtain a copy of the updated version of php.xml. Note that this version is only experimental; please be sure to keep a backup copy of the original PHP edit mode file that came with your jEdit installation.
To use the new edit mode, just replace the original with the new one, then either restart jEdit, or select Utilities | Troubleshooting | Reload Edit Modes. Edit modes are automatically selected by file extension (e.g. .php), but they can also be manually selected for any file extension in the current buffer through Utilities | Buffer Options | Edit mode.
PHP 4 Parser
One of the plugins recommended above was PHPParser. This is a PHP 4 parser that checks for syntax errors in a PHP file when the file is loaded or saved (provided you select those options using Plugins | Plugin Options | PHP Parser). Any error will be underlined in the text area, and if you’ve installed the ErrorList plugin and set it to automatically display on error (using Plugins | Plugin Options | Error List), a popup message box will also describe the PHP syntax error(s). Like syntax highlighting, this is another handy feature for diagnosing bugs at an early stage.
The author of PHPParser is currently too busy to add PHP 5 support, but he is working on adding some other features to the plugin.
The FTP plugin works with both regular and secure FTP servers, using either active or passive FTP. It provides the ability to browse directories and edit files remotely. To access its functions click on Plugins | FTP.
jEdit has a neat feature called "folding." It allows code to be collapsed or expanded based either on its indentation, or through the use of "fold markers" (not to be confused with regular markers, which allow you to quickly jump to other locations in a file). The fold markers are
}}}, and are placed on the lines before and after the lines to be collapsed and expanded.
To use these fold markers, one must turn on "explicit" folding. Folding options are set for the current buffer (i.e., file) under Utilities | Buffer Options | Folding mode, or for all files under Utilities | Global Options | Editing | Folding mode. To use folding marks, add extra comment lines to your PHP (or HTML) code and put the open- and close- folding marks in the comments.
The standard installation of jEdit comes with a collection of useful macros, which are found in the lower half of the Macros menu. There is also a macro recorder at the top of the same menu. Part III of the jEdit user’s guide, which can be accessed via Help | jEdit Help, covers "Writing Macros." jEdit uses BeanShell as its macro scripting language.
HTML/XHTML and XML
The XML plugin provides tag and entity completion, matching tag highlighting, and graphical editing of tag attributes for HTML/XHTML and XML files (depending on the file extension, e.g., .html). It’s not as full-featured as some HTML tag creation tools in other editors, but it is handy nonetheless. The XML plugin also validates XML files against their DTD.
Additional HTML and XML plugins are available.
For support beyond the user’s guide, visit the jEdit Community site.
The core developer of jEdit is Slava Pestov. Thanks to Justin Hagstrom who provided information to me on PHP syntax highlighting, and to Matthieu Casanova who wrote the PHPParser plugin and provided further information to me.