MESI Support
Multi-Edit
Support Forums
Development Forums

Creating basic PHP syntax validation support.


REQUIRED:
Multi-Edit Version 9.0 or greater.
PHP CGI version installed locally.

This article will demonstrate how to create a compiler entry that performs basic PHP syntax validation. The CGI version of PHP will need to be installed locally.

ADDING THE COMPILER ENTRY
The Compiler/Program dialog is accessed via the extension setup dialog as each list of compiler entries are associated with a file extension. To open the Compiler/Program dialog, first open the Extension Setup dialog by selecting Tools | Customize from the menu bar, then select the General tree item and click on the Filename Extensions button, select PHP from the list and click Edit. Alternatively, if a PHP file is loaded, you could right click within the file and select Extension Setup from the context menu. While viewing the Extension Setup Dialog, click on the Compiler/Program Setup button located in the lower right corner.

With the Compiler/Program dialog open, click the Insert button. The compiler setup dialog will now be displayed allowing you to enter the configurations we need.

The first thing to add is a description. This will make this compiler entry distinguishable from others that may already exist. In the Description field, I entered PHP Syntax Validator. We then need to add the command line that will be run when we execute the PHP Syntax Validator. In the Command field, enter the following command substituting your path to php.exe for the one I used.

<LFN>d:\php\php.exe -l <FILE>.<EXT>

Here's what the above command does...

  • <LFN> Specifies to use Long File Names as opposed to the 8.3 format.
  • d:\php\php.exe -l Call php passing the "Syntax Check Only" parameter (that's an 'L' not an 'i' btw).
  • <FILE>.<EXT> Passes the currently loaded (and viewed) file.

CONFIGURING ERROR PROCESSING
Don't close that Compiler Setup dialog yet. There's still one more thing to do. Click on the '...' button which is located within the Program Type group box. The Program Type name is a little misleading since we are actually adding error processing but that is because this dialog offers other functionality that is beyond the scope of this article (don't you hate coming across that phrase?). You should now have the Compiler Program Type dialog open, click on the Insert button to add a new program type. We'll need to enter values in three fields here. The first is the Type field. I used the same name as the compiler entry, PHP Syntax Validator. The other two fields we need to enter values in are for the error processing. These are the Search and Replace fields located in the Regular Expressions group box. Enter the following in the Search field

\<b\>(.*)\</b\>:(.*)\<b\>(<p>)\</b\>.*\<b\>(.*)\</b\>.*

This is a regular expression search which uses grouping to find the file, error message and line number the error occured on. Enter the following line in the Replace field.

/F=\2/M=\0/L=\5

Multi-Edit uses this replace value to display the error information and place the cursor at the line the error occured in.

FINISHING UP
Just about done. All that's left to do is close all of the configuration dialogs and try it out. Be sure to click the Select button when closing the Program Type dialog.

Now just open a PHP file and create a flagrant error such as a missing paren or semi-colon and then press F9 to launch the compiler. Note that if the PHP Syntax Validator entry is the ONLY entry, then F9 will automatically run that entry. If you have other compiler entries you'll first be prompted as to which you would like to run.

If you have any questions or comments on this article, or you would like to post an article of your own, please send an email to support@multieditsoftware.com.


Multi-Edit The Programmer's Tool of Choice