Sublime Text 3 - PHP构建系统

5

我正在努力处理这个问题。

尝试添加PHP构建系统,以下是我的代码:

{
    "cmd" : ["php", "$file"],
    "file_regex": "php$",
    "selector"  : "source.php"
}

现在,创建一个名为test.php的文件,其中包含:<?php echo "Hello, World!"; ?>会产生以下错误:
[WinError 2] The system cannot find the file specified
[cmd: ['php', 'D:\\www\\sandbox\\php\\test.php']]
[dir: D:\www\sandbox\php]

我的PATH中一定包含了PHP,并且通过命令行运行php test.php是有效的。

有人能够解释一下吗?


只是瞎猜,但也许将 $file 放在引号中会更好。因此,使用"'$file'" - Jonathan Kuhn
不,它只是在错误信息中的路径周围添加了双引号。 - rgin
你是否使用与自己相同的用户运行ST?确保该用户的PATH也已设置好。 - Sergey Telshevsky
@sergey - 我不确定在使用不同用户时会有什么影响,因为只有一个用户,而且我是在Windows机器上。另外,当我说“PATH”时,我指的是Windows的环境路径。我想我应该在我的问题中更清楚一些。 - rgin
4个回答

15

PHP.sublime-build:

{
    "cmd": ["C:\\php\\php.exe", "$file"],
    "file_regex": "php$",
    "selector": "source.php"
}

变量为指向 php.exe 文件路径的唯一方式("C:\php\php.exe")。保存后,在您的 PHP 代码上按 F7。希望这能帮助到某些人。


4

您只需要将路径更改为您的php.exe

例如,我使用wampserver,因此我的php.exe位于C:\wamp64\bin\php\php5.6.16下,这样解决方案就是:

{
    "cmd": ["C:\\wamp64\\bin\\php\\php5.6.16\\php.exe", "$file"],
    "file_regex": "php$",
    "selector": "source.php"
}

对我来说,这很有效,祝你好运 :)


-1
修改后的代码:

{ 
   "cmd": ["C:\\xampp\\php\\php.exe", "$file"],
   "file_regex": "*",
   "selector": "source.php"
}

更正:{ "cmd": ["C:\xampp\php\php.exe", "$file"], "file_regex": "*", "selector": "source.php" } - Glenn
3
你可以编辑自己的帖子 - 这可能是在这里应该做的事情。 - Rob Baillie

-1
这是我用来在终端/浏览器中运行PHP脚本的构建系统。
{
"shell_cmd": "php -l \"$file\"",
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "embedding.php",
"variants": 
[
    {
        "shell_cmd": "gnome-terminal -- bash -c \"php $file;echo;echo Press enter to exit...;read\"", 
        "name": "Run(terminal)"
    },
    {
        "shell_cmd":"firefox \"localhost/$file_base_name.php\"", 
        "name":"Run on Server"  
    }
]

}


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接