PHP关闭标签显示,我做错了什么?

时间:2022-09-20 19:15:08

I'm putting in my php to echo out just a basic html hello world paragraph and it seems to work okay except for the fact every time I'm getting the ending ;?> tag showing in my website.

我正在放入我的php来回应一个基本的html你好世界段落它似乎工作正常,除了每次我得到结束的事实;?>标签显示在我的网站。

My code looks like the below:

我的代码如下所示:

   <?php
   echo "<p>Hello World.</p>";
   ?>

Frankly this happens with any php I have inserted into my html file but i figure I would just show a simple example here. Any reason why this would happen? The

坦率地说,这种情况发生在我插入到我的html文件中的任何php中,但我想我会在这里展示一个简单的例子。这会发生什么原因?该

update with exapmple:

用exapmple更新:

Hello World.

"; ?> Thanks.

3 个解决方案

#1


PHP tags will work in file with .php extension only. If you provide .html file to the server , it will treat it as simple html as if it has NO server side content,it will just send the file as it is to browser without processing it.So in short in .HTML file , tags are not getting processed by server.

PHP标记只能在.php扩展名的文件中使用。如果你将.html文件提供给服务器,它会将它视为简单的html,好像它没有服务器端内容,它只是将文件原样发送到浏览器而不处理它。所以简而言之.HTML文件,标签未被服务器处理。

Edit : you can configure your webserver to also thread *.html as php, but it seems you haven't. First try renaming your .html to .php

编辑:你可以配置你的网络服务器也将* .html作为php线程,但似乎你没有。首先尝试将.html重命名为.php

#2


You are naming your php files as .html and your server is not configured to parse .html files for PHP code.

您将PHP文件命名为.html,并且您的服务器未配置为解析PHP代码的.html文件。

If you're using the Apache web server, you can add this configuration by adding a .htaccess file to the web root of your project directory, containing this:

如果您正在使用Apache Web服务器,则可以通过将.htaccess文件添加到项目目录的Web根目录来添加此配置,其中包含:

AddType application/x-httpd-php .html .htm

#3


You have to escape the php by \ Or you can echo separately:

\你必须通过\来逃避PHP或者你可以单独回应:

<?php
echo "<html>"; 
echo "<body>";
echo "<p>Hello World.</p>";
echo "</body>";
echo "</html>"
?>

#1


PHP tags will work in file with .php extension only. If you provide .html file to the server , it will treat it as simple html as if it has NO server side content,it will just send the file as it is to browser without processing it.So in short in .HTML file , tags are not getting processed by server.

PHP标记只能在.php扩展名的文件中使用。如果你将.html文件提供给服务器,它会将它视为简单的html,好像它没有服务器端内容,它只是将文件原样发送到浏览器而不处理它。所以简而言之.HTML文件,标签未被服务器处理。

Edit : you can configure your webserver to also thread *.html as php, but it seems you haven't. First try renaming your .html to .php

编辑:你可以配置你的网络服务器也将* .html作为php线程,但似乎你没有。首先尝试将.html重命名为.php

#2


You are naming your php files as .html and your server is not configured to parse .html files for PHP code.

您将PHP文件命名为.html,并且您的服务器未配置为解析PHP代码的.html文件。

If you're using the Apache web server, you can add this configuration by adding a .htaccess file to the web root of your project directory, containing this:

如果您正在使用Apache Web服务器,则可以通过将.htaccess文件添加到项目目录的Web根目录来添加此配置,其中包含:

AddType application/x-httpd-php .html .htm

#3


You have to escape the php by \ Or you can echo separately:

\你必须通过\来逃避PHP或者你可以单独回应:

<?php
echo "<html>"; 
echo "<body>";
echo "<p>Hello World.</p>";
echo "</body>";
echo "</html>"
?>