简体   繁体   English

PHP - 'print / echo'显示结束标记 - 或不输出

[英]PHP - 'print/echo' displaying closing tags - or not outputting

Starting some PHP and confused by the way echo/print are working. 启动一些PHP,并对echo / print的工作方式感到困惑。

I've got this code in my index.html : 我的index.html有这个代码:

<?php
Print '<div>Hello, World!</div>';
?>

And the output on my page is 我页面上的输出是

Hello, World!'; ?> 

If I remove the <div> tags, I get no output. 如果我删除<div>标签,我没有输出。 using echo produces the same behaviour. 使用echo产生相同的行为。

What's going on? 这是怎么回事? Everything I find on Google makes it seem straight forward. 我在Google上找到的所有内容都让它看起来很简单。

You cannot put PHP code in an HTML file (unless you tell Apache to parse HTML files). 您不能将PHP代码放在HTML文件中(除非您告诉Apache解析HTML文件)。

Rename the file to index.php 将文件重命名为index.php

Do you have a webserver with PHP set-up? 你有一个PHP设置的网络服务器吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM