It’s sort of a tradition that the first program you write in any language is the Hello World program. You may have written a Hello World program in HTML when you first learned it. If you did, it probably looked similar to the following HTML file:
<html>
<head><title>Hello World HTML Program</title></head>
<body>
<p>Hello World!</p>
</body>
</html>
If you point your browser at this HTML program, you see a Web page that displays the following output in the browser window:
Hello World!
Your first PHP script is a script that does exactly the same thing. The following code is a PHP script that includes both HTML and PHP code and displays Hello World! in a browser window:
<html>
<head><title>Hello World Script</title></head>
<body>
<?php
echo “<p>Hello World!</p>”
?>
</body>
</html>
If you point your browser at this script, it displays the same Web page as the HTML script.
Don’t look at the file directly with your browser. That is, don’t choose File➪Open➪Browse from your browser menu to navigate to the file and click it.
You must point at the file by typing its URL, as discussed in Chapter 2. If you see the PHP code displayed in the browser window, instead of the output you expect, you may not have pointed to the file by using its URL.
In this PHP script, the PHP section consists of the following code:
<?php
echo _<p>Hello World!</p>_
?>
The PHP tags enclose only one statement - an echo statement - that simply outputs the text between the double quotes.
When the PHP section is processed, it is replaced with the output. In this case, the output is as follows:
<p>Hello World!</p>
If you replace the PHP section in the HTML version of Hello World with the preceding output, the script now looks exactly like the HTML program. If you point your browser at either program, you see the same Web page. If you look at the source code that the browser sees (in the browser, choose View➪ Source), you see the same source code listing for both programs.
0 comments:
Post a Comment