Home > Articles > Programming > PHP

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Basic Page Structure

Once PHP is installed, creating a page is simple. Like an HTML page, a PHP page is simply text with a particular extension. Most PHP pages use .php, but older pages labeled .phtml and .php3 are also common. Pages can use any extension supported by the web server.

A PHP page may contain both static and dynamic information, with the dynamic information enclosed between the start delimiter (<?php) and the end delimiter (?>). For example, Listing 1 shows a very simple page, with the PHP section in bold.

Listing 1—A Simple PHP Page Named calendar.php

<html>
<head><title>Event Calendar</title></head>
<body>
<h1>This Month's Events</h1>
<?php
  echo ("The calendar goes here.");
?>
</body>
</html>

Save the file as calendar.php in the appropriate web server directory and open it with your browser. Make sure that you're actually calling the server, using a URL such as this http://localhost/calendar.php, not file:///c|/calendar.php.

The result should look like Figure 1.

Figure 1Figure 1 The basic page.

If you look at the source for the web page, you'll see that the section between <?php and ?> was processed by the server and returned to the browser as plain old HTML, as shown in Listing 2.

Listing 2—The Source Received by the Browser

<html>
<head><title>Event Calendar</title></head>
<body>
<h1>This Month's Events</h1>
The calendar goes here.
</body>
</html>

In this case, the code was simple; echo() simply outputs text to the page. But you could provide any kind of processing in this section, and all the browser will see is text that's output explicitly.

  • + Share This
  • 🔖 Save To Your Account