在HTML页面中显示Php回显消息

在HTML页面中显示Php回显消息

本文介绍了在HTML页面中显示Php回显消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是网络开发的新手.我正在尝试在HTML页面中显示来自php文件的回显消息.

Hi I am a newbie to web development. I am trying to display echo message from a php file in html page.

PHP文件:

<?php
    echo "Hello";
?>

其他文件:

<form method="get" action="latest.php">

</form>

注意:这都是两个不同的文件

Note: These both are two different files

我对此完全陌生.我不知道我要去哪里错了.

I am completely new to this. I don't know where I am going wrong.

推荐答案

通常,您只能在扩展名为.php的文件中执行PHP代码,因为您的Web服务器的设置与PHP相似.但是,您可以简单地告诉Web服务器将HTML文件也解析为PHP,然后就可以在所需的HTML文件中运行PHP代码.现在假设您的Web服务器是Apache.

Normally, you can only execute PHP code in a file which has .php extension because your webserver is setup like that for PHP. However you can simply tell your web server to parse your HTML files as PHP too and then you can run your PHP code in an HTML file wherever you want. Now assuming your Web server is Apache.

第1步:

创建一个名为.htaccess的文件,并将以下代码放入其中,然后将该文件放入该网站的根目录中

Create a file named .htaccess and place the following code in it and then place this file in your root directory for that website

AddType application/x-httpd-php .html

第2步:

转到您的HTML文件并在要包含PHP文件的位置添加一个include语句

Go to Your HTML file and add an include statement where you want your PHP file to be included

<form method="get" action="latest.php">
<?php include ("yourPHPfile.php"); ?>
</form>

第3步:

全部完成,现在在浏览器中检查输出.

All done, now go check output in browser.

这篇关于在HTML页面中显示Php回显消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 07:54