Sublime Text 2 中运行 PHP

2013/12/09 10:34
阅读数 4.1K

Sublime Text 2 has the concept of build systems. This basically means that if you are editing a Python file then you can run the Python interpreter on the source file your are editing and see the output in a console window, all without having to leave the Sublime editor. It’s surprising how much quicker and easier this is compared to having to leave Sublime to swap to a separate console window.

This is Sublime’s Tools->Build System menu system menu-tools

Surprisingly, there is no supplied build system for PHP, to add one go to “New Build System”. A new tab opens for file untitled.sublime-build with the following in it:

<!-- lang: js -->
{ “cmd”: [“make”] }

Delete that and replace it with this:

<!-- lang: js -->
{ “cmd”: [“php”, “$file”], “file_regex”: “php$”, “selector”: “source.php” }

And save the file. Sublime will pop up the file save dialog, which defaults to the directory that Sublime uses for its user-generated config files, so don’t change the directory, just save this file as php.sublime-build. Now, when you edit a file whose name ends with php (as specified by the “php$” regex in the config file) you will have a build system available. You can now hit CTRL+B and the PHP interpreter will run against your source file and the output appears in a Sublime Text window.

sublime-build-php

The grey window shows the output of the PHP interpreter and the time it took to run.

展开阅读全文
加载中

作者的其它热门文章

打赏
0
4 收藏
分享
打赏
0 评论
4 收藏
0
分享
返回顶部
顶部