如何在Sublime Text 2中运行PHP代码 [英] How to run PHP code in Sublime Text 2
问题描述
我对Sublime text 2还是陌生的.我刚刚开始使用它,对此一无所知.我想在PHP上工作.我已经建立了一个系统"PHP".选择"php"构建系统后,我将创建一个新文件,并仅用一条回显线编写PHP代码并尝试运行它.每当它给我这个错误
I am very new to Sublime text 2. I have just started using this and know nothing about it. I want to work on PHP. I have built a system 'php'. After choosing 'php' build system I am creating a new file and writing PHP code with just a single echo line and trying to run it. Everytime it is giving my this error
默认情况下,Sublime Text 2保存在C:\ Program Files \ Sublime Text 2中
By default Sublime Text 2 saved in C:\Program Files\Sublime Text 2
,自动保存文件的路径是 C:\ Users \ SM Ahmed \ AppData \ Roaming \ Sublime Text 2 \ Packages \ User
and the path where automatically files are being saved is C:\Users\SM Ahmed\AppData\Roaming\Sublime Text 2\Packages\User
该怎么做才能使我的代码成功运行
What should I do that makes my code run succesfully
推荐答案
虽然传统上PHP脚本由Web服务器运行,但可以通过Sublime运行它们.要设置网络服务器,建议您阅读以下内容: http ://www.ntu.edu.sg/home/ehchua/programming/howto/WampServer_HowTo.html
While traditionally PHP scripts are run by web servers, it is possible to run them through Sublime. To set up a webserver, I suggest you to read this: http://www.ntu.edu.sg/home/ehchua/programming/howto/WampServer_HowTo.html
它将帮助您开始设置本地服务器和运行" PHP.
It will get you started on how to setup a local server and 'run' PHP.
如果要从Sublime Text 2/3控制台运行PHP,则应转到:
If you want to run PHP from your Sublime Text 2/3 console you should go to:
Tools -> Build System -> New Build System...
,然后按如下所示编辑文件:
and then edit the file like this:
{
"cmd": ["/path/to/php", "$file"]
}
其中,/path/to/php
类似于Linux/OS X上的/usr/local/bin/php
或Windows上的C:/WAMP/bin/php.exe
(请确保使用正斜杠/
).将文件另存为Packages/User/PHP.sublime-build
,其中Packages
是选择Preferences -> Browse Packages...
时打开的文件夹.接下来,点击Tools -> Build System -> PHP
并点击 Ctrl + B 来运行脚本(或 Cmd + B 苹果机).您应该会在打开的构建控制台中看到输出(如果有的话).
where /path/to/php
is something like /usr/local/bin/php
on Linux/OS X or C:/WAMP/bin/php.exe
on Windows (make sure to use forward slashes /
). Save the file as Packages/User/PHP.sublime-build
where Packages
is the folder opened when you select Preferences -> Browse Packages...
. Next, click on Tools -> Build System -> PHP
and hit Ctrl+B to run your script (or Cmd+B on a Mac). You should see the output, if any, in the build console that opens.
请确保您的PHP中没有任何错误,并且请确保已正确配置 PHP !
Be sure there aren't any errors in your PHP and also be sure that PHP is configured correctly!
这篇关于如何在Sublime Text 2中运行PHP代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!