HTML 中的 PHP 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22939278/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:22:53  来源:igfitidea点击:

PHP inside HTML doesn't work

phphtmlecho

提问by user3511259

I just want to know why does this HTML file shows nothing:

我只想知道为什么这个 HTML 文件什么都不显示:

  • I'm running it on a web server
  • Name of the file is index.php
  • I've fixed the <?issue but it still doesn't work
  • 我在网络服务器上运行它
  • 文件名是 index.php
  • 我已经解决了这个<?问题,但它仍然不起作用

Here's the code:

这是代码:

<html>
<head>
</head>
<body>
            <?php
            echo "hdfguhbgzusgdfghdhhfgh";       
            ?>
</body>
</html>

回答by Gizzmo

You should make sure that following are given:

您应该确保提供以下内容:

  • PHP on your server

  • Files have to end with ".php"

  • Use open Tag <?phpand not <?

  • 您服务器上的 PHP

  • 文件必须以“.php”结尾

  • 使用 open Tag<?php而不是<?

Then it should work.

那么它应该工作。

For a definite solution you should provide further information.

对于明确的解决方案,您应该提供更多信息。

回答by Smart People Help Others

As edited by halferon Apr 8 '14 at 14:13, the showing code had no <?problem anymore. The code seemed well written.

正如halfer2014年 4 月 8 日 14:13编辑的那样,显示代码<?不再有问题。代码看起来写得很好。

In case those code still do not work, perhaps people must add:

如果这些代码仍然不起作用,也许人们必须添加:

AddHandler application/x-httpd-php .html

inside the .htaccessfile.

.htaccess文件里面。

The .htaccessfile must be in the same directory with your htmlfile. If you can't found the .htaccessfile although you already turning on the show hidden file option, you can create new .htaccessfile and include AddHandler mentioned above in the file.

.htaccess文件必须与您的html文件在同一目录中。如果您.htaccess在打开显示隐藏文件选项后仍找不到该文件,则可以创建新.htaccess文件并在文件中包含上述 AddHandler。

Just create a blank text file and name it with .htaccesson the mentioned directory.

只需创建一个空白文本文件并.htaccess在提到的目录中命名它。

回答by ponciste

you missed phpafter <?

你错过了php<?

so, change:

所以,改变:

<? echo "hdfguhbgzusgdfghdhhfgh";  ?>

with

<?php echo "hdfguhbgzusgdfghdhhfgh";  ?>

回答by Jan Matou?ek

Some tips:

一些技巧:

  • If you dont see the text, try to open source code in browser.
  • Make sure, that your file is .php and not .html
  • Use <?phpas opening tag instead <?
  • If you want to just echo text, you can use <?echo "YourText"; ?>
  • 如果看不到文字,请尝试在浏览器中打开源代码。
  • 确保您的文件是 .php 而不是 .html
  • 使用<?php如打开的标签,而不是<?
  • 如果你只想回显文本,你可以使用 <?echo "YourText"; ?>

Everything else seems OK

其他一切似乎都还好

回答by juniorb2s

The short_tags comes disabled by default, so you have to use

默认情况下禁用 short_tags,因此您必须使用

<?php
  echo 'Teste';   
?>

invés de:

投资于:

<?
  echo 'Teste';   
?>

To enable the option to just turn short_tag in php.ini http://www.php.net/manual/en/ini.core.php#ini.short-open-tag

要启用仅在 php.ini 中打开 short_tag 的选项 http://www.php.net/manual/en/ini.core.php#ini.short-open-tag

PS: For performance reasons it is recommend to use "(double quotes) only when the echo is variable, so that PHP will parse and find the variable If you place." (Double quotes) there is no variable in the php echo to atoa parsing, try waste of charge.

PS:出于性能原因,建议只在echo为变量时使用“(双引号),这样PHP会解析并找到变量如果你放置。” (双引号)php echo to atoa 解析中没有变量,尝试浪费。