Low cost ecommerce web development India flash website design
Your First PHP Script
It would be unfair of me to help you get everything installed and not even give
you a taste of what a PHP-driven Web page looks like until Chapter 3, so here's
a little something to whet your appetite.
Open up your favourite text or HTML editor and create a new file called
today.php. Windows users should note that, to save a file with a .php extension
in Notepad, you'll need to either select All Files as the file type, or surround the
file name with quotes in the Save As dialogue; otherwise, Notepad will helpfully
save the file as today.php.txt, which won't work. Mac OS users are advised not
to use TextEdit to edit .php files, as it saves them in Rich Text Format with an
xxiihttp://www.mysql.com/products/mysqlgui/
30
Installation
invisible .rtf file name extension. Learn to use the vi editor in a Terminal window
or obtain an editor that can save .php files as plain text.
Whichever editor you use, type this into the file:
<html>
<head>
<title>Today's Date</title>
</head>
<body>
<p>Today's Date (according to this Web server) is
<?php
echo( date('l, F dS Y.') );
?></p>
</body>
</html>
If you prefer, you can download this file along with the rest of the code in this
book in the code archive. See the Introduction for details on how to download
the archive.
Save this material, and place it on your Website as you would any regular HTML
file, then view it in your browser. Note that if you view the file on your own
machine, you cannot use the File, Open feature of your browser, because your Web
server must intervene to interpret the PHP code in the file. Instead, you must
move the file into the root document folder of your Web server software (e.g.
C:\inetpub\wwwroot\ in IIS, or C:\Apache Group\Apache\htdocs\ in Apache
for Windows), then load it into your browser by typing http://localhost/
today.php. This process allows the Web server to run the PHP code in the
file and replace it with the date before it's sent to the Web browser. Figure 1.1
shows what the output should look like.
31
Your First PHP Script
Figure 1.1. Output of today.php
Pretty neat, huh? If you use the View Source feature in your browser, all you'll see
is a regular HTML file with the date in it. The PHP code (everything between
<?php and ?> in the code above) has been interpreted by the Web server and
converted to normal text before it's sent to your browser. The beauty of PHP,
and other server-side scripting languages, is that the Web browser doesn't have
to know anything about it — the Web server does all the work!
And don't worry too much about the exact code I used in this example. Before
too long you'll know it like the back of your hand.
If you don't see the date, then something is wrong with the PHP support in your
Web server. Use View Source in your browser to look at the code of the page.
You'll probably see the PHP code there in the page. Since the browser doesn't
understand PHP, it just sees <?php ... ?> as one long, invalid HTML tag, which
it ignores. Make sure that PHP support has been properly installed on your Web
server, either in accordance with the instructions provided in previous sections
of this chapter, or by your Web host.
website designer freelance ASP PHP ecommerce web developer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110