简体   繁体   中英

unexpected php behavior

I'm trying to learn php but something goes wrong... When I use this code:

<html>
<head>
<title>My first PHP page</title>
</head>
<body>

<?php   

echo "<h1>Hello World!</h1>";

?>

</body>
</html>

I'm supposed to just get Hello World! In stead I get: Hello World!"; ?> However if I just take the php code, save it as a .php file and point my browser to that file it shows Hello World in big bold letters like you'd expect. I've tried it om my own computer (with apache and PHP 5.3.15 running) and on the server of my provider with the same faulty results. I've tried different browsers, different computers. I've also tried other examples from other tutorials (the above example is the most simple that goes wrong) but none of those work as they should. Reading a text file with the include() function works when I open just the .php file but returns an empty canvas when embedded in an html file. I have not yet written a word of code myself, everything is copy/paste so what can be wrong? Try at http://www.raadvanarbeid.nl/index2.html and http://www.raadvanarbeid.nl/index2.php for the example above.

您必须将.html文件重命名为.php,以便服务器知道它应该呈现文件。

The file needs to be interpreted by the PHP interpreter. Thus you need a webserver to shunt it off to the PHP interpreter, and you need to name the file so that the webserver knows it's meant to be processed by the PHP interpreter. That's why the name of the file needs to end in '.php' and why you get different results when you access the file directly versus though a webserver.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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