EmEditorみんなでまとめサイト

php構文チェッカー

最終更新:

匿名ユーザー

- view
だれでも歓迎! 編集

php構文チェッカー

文章がphpの時だけCtrl+Sにでもマクロを割り当ててください。
文章が保存されていないとき(更新された時)のみ保存してから
phpの構文チェックをかけます。
問題がなければステータスバーにNo syntax errorの表示を行い、
問題があれば新しいテキストファイルを作成しエラー内容を書き出します。

/**
 * phplint.jsee
 * @package  emeditor wiki
 * @required php for windows
**/

/**
 * メイン関数
 */
function phplint()
{
    if(!document.Saved)
    {
        try{
            document.Save(document.FullName);
        
            wshshell = new ActiveXObject("Wscript.shell");
            file     = document.Path + "\\" + "phplint";

            cmd      = "cmd /c php -l \"";  //リダイレクトを使いたいので
            command  = cmd + document.FullName + "\" > \""+ file +"\"";
            wshshell.run(command, 0, true);

            content = doFile(file, 2);      //ファイル読み込み
            checkFile(content);             //文字列内容検査
            doFile(file, 1);                //構文解析ファイル削除
        }catch(e){
            raiseError(e);
        }
    }
}

/**
 * エラー表示
 *   raiseError(string);
 */
function raiseError(e)
{
    alert(e);
}

/**
 * ファイル読みこみ・削除
 *   doFile(ファイルパス,type)
 *      type = 1 該当ファイルを削除
 *      type = 2 該当ファイルを読み込み 
 * return content;
 */
function doFile(_file,_type)
{
    FSO = new ActiveXObject("Scripting.FilesystemObject");
    if(FSO.FileExists(_file))
    {
        switch(_type)
        {
            case 1:
                FSO.DeleteFile(_file);
                return true;
            default:
                fd       = FSO.OpenTextFile(_file,1,0,-2);
                content  = fd.ReadAll();
                fd.Close();
                return content;
        }
    }
}

/**
 * 構文解析ファイルの文字列をチェック
 *   checkFile(string)
 * return boolean;
 */
function checkFile(_content)
{
    //構文解析した内容にkeywordがあればok
    //なければエラーとみなす。
    keyword = "No syntax"
    if(_content.search(keyword)!==-1)
    {
        status = "No syntax error";
        return true;
    }else{
        Editor.NewFile();
        document.write(_content);
        return false;
    }
}

phplint();

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

目安箱バナー