如何在html文件中实现php [英] how to implement php in html file

查看:121
本文介绍了如何在html文件中实现php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我基本上是全新的基于网络的东西。我的大学给了我一个cPanel托管的服务器。我需要为我的主网​​页实现一些基本的PHP功能。



这是我的cPanel看起来像是有帮助的:





所以在我的index.html文件中我有:

 <!DOCTYPE html> 
< html>
< head>
< title>当前日期/时间< / title>
< / head>

< body>
< h3>
<?php
date_default_timezone_set('UTC');
回声日期(l);
回声Hello World!;
?>
< / h3>
< / body>
< / html>

但是没有显示任何php回显内容。我不确定我的服务器是否真的知道如何处理带有php的html文件。



我的教师告诉我:需要部署php文件到使用CPanel中的文件管理器的public_html文件夹。



但我不确定需要进入.php文件以及如何让我的.html文件利用它。



感谢您的耐心等待。

解决方案

该文件的扩展名需要从* .html更改为* .php,否则PHP将无法执行,我们将仅仅被视为原始的HTML。



下面是一个快速的非常基本的一步一步发生的事情:


  1. 客户端请求index.php


  2. 您的web服务器识别* .php扩展名并告诉PHP解释PHP解析查找PHP代码的文本,并评估代码,然后用该PHP代码的输出替换PHP代码(如果有的话) / p>

    例如:

      $ strVar ='world'; 
    echo'< span class =contentText> hello'。 $ strVar。 '< / span>< br />';

    被替换为该代码的输出:

     < span class =contentText> hello world< / span>< br /> 


  3. 然后将生成的HTML返回给客户端,作为客户端web呈现的内容浏览器


  4. 客户端的Web浏览器解析HTML并呈现网页


so I'm basically brand new to web based stuff. My university has given me a cPanel hosted server. I need to implement some basic php functions for my main web page.

This is what my cpanel looks like if it helps:

So in my index.html file I have:

<!DOCTYPE html>
<html>
<head>
<title>Current Date/Time</title>
</head>

<body>
<h3>
<?php
date_default_timezone_set('UTC');
echo date("l");
echo "Hello World!";
?>
</h3>
</body>
</html>

But none of the php echo stuff is displaying. I'm not sure if my server actually knows what to do with an html file with php in it.

My instructors have told me: the php file needs to be deployed to public_html folder using the file manager in CPanel.

But i'm not really sure what needs to go into the .php file and how to get my .html file to utilize it.

Thanks for your patience.

解决方案

The file's extension needs to be changed from *.html to *.php or the PHP won't execute, it'll just be treated like raw HTML.

Here's a quick very basic step-by-step of what's happening:

  1. The client requests index.php

  2. Your web server recognizes the *.php extension and tells PHP to interpret it

  3. PHP parses the text looking for PHP code, and evaluates that code, then replaces the PHP code with the output of that PHP code (if any)

    For example:

    $strVar = 'world';
    echo '<span class="contentText">hello ' . $strVar . '</span><br />';
    

    is replaced with that code's output:

    <span class="contentText">hello world</span><br />
    

  4. The resulting HTML is then returned to the client as content to be rendered by the client's web browser

  5. The client's web browser parses the HTML and renders a web page

这篇关于如何在html文件中实现php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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