如何从 Visual Studio Code (VSCode) 运行 PHP 代码? [英] How to run PHP code from Visual Studio Code (VSCode)?

查看:333
本文介绍了如何从 Visual Studio Code (VSCode) 运行 PHP 代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到在 Visual Studio 代码上运行 php 的方法,有人知道怎么做吗?

重复:

是的,它与

  • 在 VSCode 中安装 PHP 调试扩展
  • 然后配置php.ini文件
  • 在根文件夹中创建一个外部php文件
  • 添加<代码> 在我现在创建的外部 php 文件中
  • 在我的 index.html 文件中,我引用了我的 php 文件,例如:
  • 使用 xampp 控制面板运行我的 Web 服务器 apache
  • 构建我的项目并在网络浏览器上运行它,它什么也没显示.
  • 此外,当我打开 chrome 浏览器的开发工具时,它会显示我的 php 索引文件代码注释.为什么?我不知道.
  • 问题:

    我在上面的步骤中做错了什么来在 vs 代码中配置 php.请用简单的步骤向我解释,这样我就可以轻松实现我的目标.提前致谢.

    解决方案

    看起来您实际上并不想要从 Visual Code 运行 PHP,而是试图让 PHP 运行工作.

    <块引用>

    1. 添加外部php文件我现在创建的

    您使用的是短标签没关系,如果您的配置允许的话,但是我建议使用显式 PHP 标签:<?php echo "My First PHP site in VSCode.";?>

    <块引用>

    在我的 index.html 文件中,我引用了我的 php 文件,例如:

    问题来了.您将 PHP 代码放置在 HTML 文件中.HTML 文件中的 PHP 代码不会(至少默认情况下)不会被执行.将文件名index.html 更改为 index.php.

    应该可以.

    I can't find a way to run php on Visual studio code, Does anyone know how?

    Duplicate:

    Yes it is but a little bit different from here.

    Steps:

    I followed below steps to configure php in VS Code.

    1. Configure PHP linting in user settings
    2. Install Php Debug extension in VSCode
    3. Then configure php.ini file
    4. Create a external php file in root folder
    5. add <? echo "My First PHP site in VSCode."; ?> in external php file which I created now
    6. In my index.html file I referenced my php file like:
    7. Run my web server apache using xampp control panel
    8. Build my project and run it on web browser it shows me nothing.
    9. Also when I open dev tools of my chrome browser its shows me my php code of index file commented. why? I don't know.

    Question:

    What I am doing wrong in my above steps to configure php in vs code. Please explain me in easy steps so I can easily achieve my goal. Thanks in advance.

    解决方案

    Looks like you in fact don't want to run PHP from Visual Code, but instead you're trying to get PHP to work at all.

    1. add in external php file which I created now

    You're using short tags and that's ok, if your configuration allows it, however I would recommend using explicit PHP tags: <?php echo "My First PHP site in VSCode."; ?>

    In my index.html file I referenced my php file like:

    There's the problem. You're placing PHP code in a HTML file. PHP code in HTML files won't be (at least by default) executed. Change the filename from index.html to index.php.

    That should do it.

    这篇关于如何从 Visual Studio Code (VSCode) 运行 PHP 代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆