且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在HTML中包含php脚本

更新时间:2023-12-04 22:07:40

您会收到什么输出?它只是显示PHP代码?



我假设是这种情况。



对于测试,更改将文件扩展名为 .php 并再次运行。它现在有效吗?如果是这样,你需要将PHP与 .html 和 .htm 您服务器上的文件。



编辑



这是你要添加到你的Apache配置的行:

  AddType application / x-httpd-php。 html 


I am a newbie and have never used PHP before. I want to execute PHP script from an HTML file on Linux. What do I need to do?

This is the content of my HTML file:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
   <HEAD>
      <TITLE>Testing Weather Data</TITLE>
   </HEAD>
   <BODY>
      <div id="weather">
         <p>Weather Information
         <?php include "/home/tahoang/Desktop/weatherData.php"; ?>
      </div>
   </BODY>
</HTML>

What output do you receive? Does it just show the PHP code?

I assume that's the case.

For a test, change the extension on the file to .php and run it again. Does it work now?

If so, you will need to associate PHP with .html and .htm files on your server.

EDIT

This is the line you want to add to your Apache config:

AddType application/x-httpd-php .html