Php被html注释掉了。 [英] Php gets commented out in html.

查看:121
本文介绍了Php被html注释掉了。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的html网页,其中包含以下php代码。

 <?php echo date ('1,F jS,Y'); ?> 

当我运行html页面并查看它显示的源代码时:

 <! - ?php echo date('l,F jS,Y'); ? - > 

我做错了什么?为什么它被注释掉了?

解决方案

要运行PHP脚本,您必须将文件另存为 .php 文件。您还需要在服务器上执行它。你不能直接从你的浏览器运行php,因为PHP是一个HTML预处理器 - 你的浏览器与PHP无关,只能获得服务器生成的HTML。



因此,因为PHP标记在HTML文件中无效,所以当不由服务器预处理时,浏览器无法识别它,所以它会自动将它转换为注释,因为它不知道如何处理它。

I created a simple html webpage that includes the following php code in the html code.

<?php echo date('l, F jS, Y'); ?>

When I run the html page and I view the source code it shows :

<!--?php echo date('l, F jS, Y'); ?-->

What am I doing wrong? why is it being commented out?

解决方案

To run PHP scripts, you have to save the file as a .php file. You will also need to execute it on a server. You can't run php directly from your browser, since PHP is a HTML preprocessor - your browser has nothing to do with PHP, it only gets the HTML that is generated by the server.

So because PHP tags are not valid in HTML files, when not preprocessed by the server, the browser doesn't recognise it, so it automatically converts it to comments since it doesn't know what else to do with it.

这篇关于Php被html注释掉了。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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