如何在 Visual Studio 中使用 PHP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10529214/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use PHP with Visual Studio
提问by Code Ratchet
First let me say I've never used PHP but I'm looking to learn it, so my question is this how do you use PHP within Visual Studio Ultimate? is it similar to how you declare JQuery i.e
首先让我说我从未使用过 PHP,但我想学习它,所以我的问题是您如何在 Visual Studio Ultimate 中使用 PHP?它是否类似于您声明 JQuery 的方式,即
$(document).ready(function ()
{
// Code goes here?
});
I've done multiple searches on Google, but I don't get the answer I'm looking for.
我在 Google 上进行了多次搜索,但没有得到我想要的答案。
Or do I need a complete different bit of software to use it?
或者我需要一个完全不同的软件来使用它吗?
回答by Gabriel
By default VS is not made to run PHP, but you can do it with extensions:
默认情况下,VS 不会运行 PHP,但您可以使用扩展来实现:
You can install an add-on with the extension manager, PHP Tools for Visual Studio.
您可以使用扩展管理器PHP Tools for Visual Studio安装附加组件。
If you want to install it inside VS, go to Tools > Extension Manager > Online Gallery > Search for PHP where you will find PHP Tools (the link above) for Visual Studio. Also you have VS.Php for Visual Studio. Both are not free.
如果要在 VS 中安装它,请转到工具 > 扩展管理器 > 在线库 > 搜索 PHP,您将在其中找到 Visual Studio 的 PHP 工具(上面的链接)。你也有Visual Studio 的 VS.Php。两者都不是免费的。
You have also a cool PHP compiler called Phalanger:

你还有一个很酷的 PHP 编译器,叫做 Phalanger:

If I'm not mistaken, the code you wrote above is JavaScript (jQuery) and not PHP.
如果我没记错的话,你上面写的代码是 JavaScript (jQuery) 而不是 PHP。
If you want cool standalone IDE's for PHP: (Free)
如果你想要一个很酷的 PHP 独立 IDE:(免费)
回答by Christoph Grimmer-Dietrich
Maybe we should help you with a big misunderstanding on your side first: PHP is (like ASP.NET or whatever you used to far) a server sidelanguage while javascript is client side.
也许我们应该首先帮助您解决一个很大的误解:PHP 是(如 ASP.NET 或任何您曾经使用过的)服务器端语言,而 javascript 是客户端。
This means that PHP will run on your webserver and create a HTML page dynamically which is then sent to the browser. Javascript in turn is embedded (either directly or as a referenced file) into this HTML page and runs in the browser.
这意味着 PHP 将在您的网络服务器上运行并动态创建一个 HTML 页面,然后将其发送到浏览器。Javascript 依次嵌入(直接或作为引用文件)到此 HTML 页面中并在浏览器中运行。
Maybe you can now understand why your approach so far could never work out.
也许您现在可以理解为什么到目前为止您的方法永远无法奏效。
回答by mojmir.novak
Try Visual Studio Code. Very good support for PHP and other languages directly or via extensions. It can not replace power of Visual Studio but it is powerful addition to Visual Studio. And you can run it on all OS (Windows, Linux, Mac...).
尝试Visual Studio 代码。直接或通过扩展很好地支持 PHP 和其他语言。它无法取代 Visual Studio 的强大功能,但它是 Visual Studio 的强大补充。您可以在所有操作系统(Windows、Linux、Mac...)上运行它。
回答by Conex
Maybe it's possible to debug PHP on Visual Studio, but it's simpler and more logical to use Eclipse PDTor Netbeans IDEfor your PHP projects, aside from Visual Studio if you need to use both technologies from two different vendors.
也许可以在 Visual Studio 上调试 PHP,但是如果您需要使用来自两个不同供应商的两种技术,那么除了 Visual Studio 之外,将Eclipse PDT或Netbeans IDE用于 PHP 项目更简单、更合乎逻辑。
回答by Revious
回答by Ivan Ferrer Villa
I don't understand how other answers don't answer the original question about how to use PHP (not very consistent with the title).
PHP files or PHP code embedded in HTML code start always with the tag <?phpand ends with ?>.
我不明白其他答案如何不回答有关如何使用 PHP 的原始问题(与标题不太一致)。
PHP 文件或嵌入在 HTML 代码中的 PHP 代码始终以标记开头<?php并以?>.
You can embed PHP code inside HTML like this (you have to save the file using .phpextension to let PHP server recognize and process it, ie: index.php):
您可以像这样在 HTML 中嵌入 PHP 代码(您必须使用.php扩展名保存文件以让 PHP 服务器识别和处理它,即:index.php):
<body>
<?php echo "<div>Hello World!</div>" ?>
</body>
or you can use a whole php file, ie: test.php:
或者你可以使用整个 php 文件,即:test.php:
<?php
$mycontent = "Hello World!";
echo "<div>$mycontent</div>";
?> // is not mandatory to put this at the end of the file
there's no document.readyin PHP, the scripts are processed when they are invoked from the browser or from another PHP file.
document.readyPHP 中没有,脚本在从浏览器或另一个 PHP 文件调用时被处理。

