PHP5: PHP syntax-oriented code
1 2
3 function do_html_header ($ title)
4 {
5 // print an HTML header
6?>
7
8
9 <? Php echo $ title;?>
10
16
17
18 19 align = left valign = bottom height = 55 width = 57/>
20 PHPbookmark
21
22 23 if ($ title)
24 do_html_heading ($ title );
25}
26
27 function do_html_footer ()
28 {
29 // print an HTML footer
30?>
31
32
33 34}
35
36 function do_html_heading ($ heading)
37 {
38 // print heading
39?>
40
41 42}
43
44 function do_html_URL ($ url, $ name)
45 {
46 // output URL as link and br
47?>
48
">
49 50}
51
52 function display_site_info ()
53 {
54 // display some marketing info
55?>
56
57
- Store your bookmarks online with us!
58
- See what other users use?
59
- Share your favorite links with others?
60
61 62}
63
64 function display_login_form ()
65 {
66?>
67 Not a member?
68
85 86}
87
88 function display_registration_form ()
89 {
90?>
91
111 112
113}
114
115 function display_user_urls ($ url_array)
116 {
117 // display the table of URLs
118
119 // set global variable, so we can test later if this is on the page
120 global $ bm_table;
121 $ bm_table = true;
122?>
123
124
150 151}
152
153 function display_user_menu ()
154 {
155 // display the menu options on this page
156?>
157
158 Home |
159 Add BM |
160 161 // only offer the delete option if bookmark table is on this page
162 global $ bm_table;
163 if ($ bm_table = true)
164 echo "Delete BM | ";
165 else
166 echo "Delete BM | ";
167?>
168 Change password
169
170 Recommend URLs to me |
171 Logout
172
173
174 175}
176
177 function display_add_bm_form ()
178 {
179 // display the form for people to ener a new bookmark in
180?>
181
188 189}
190
191 function display_password_form ()
192 {
193 // display html change password form
194?>
195
196
197
198
| Old password: | 199
| 200
201
| New password: | 202
| 203
204
| Repeat new password: | 205
| 206
207
208 |
209
210
211 212 };
213
214 function display_forgot_form ()
215 {
216 // display HTML form to reset and email password
217?>
218
219
220
221
| Enter your username | 222
| 223
224
225 |
226
227
228 229 };
230
231 function display_recommended_urls ($ url_array)
232 {
233 // similar output to display_user_urls
234 // instead of displaying the users bookmarks, display recomendation
235?>
236 & nb #
This code is indeed long enough, but there is nothing in it. from the perspective of introducing syntax, the best way is to select some of the code. This part of the code is sufficient to summarize the PHP syntax. Which one is better? OK. select the display_user_urls function of row 115. the code is as follows:
1 function display_user_urls ($ url_array)
2 {
3 // display the table of URLs
4
5 // set global variable, so we can test later if this is on the page
6 global $ bm_table;
7 $ bm_table = true;
8?>
9 <br/>
10 <form name = 'bm_table 'action = 'delete_bms.php' method = 'post'>
11 <table width = 300 cellpadding = 2 cellspacing = 0>
12 13 $ color = "# cccccc ";
14 echo"Bookmark";
15 echo"Delete?";
16 if (is_array ($ url_array) & count ($ url_array)> 0)
17 {
18 foreach ($ url_array as $ url)
19 {
20 if ($ color = "# cccccc ")
21 $ color = "# ffffff ";
22 else
23 $ color = "# cccccc ";
24 // remember to call htmlspecialchars () when we are displaying user data
25 echo"". Htmlspecialchars ($ url )."";
26 echo"27 value = \ "$ url \">";
28 echo"";
29}
30}
31 else
32 echo"No bookmarks on record";
33?>
34
35
36 37}
OK. the following description takes the line number of this code segment as the standard. This function is used to display bookmarks. The input parameter is an array of bookmarks.
Look at the above code. I will start from the following aspects:
How to define the basic types of PHP variables and constant PHP operators PHP expressions PHP process control PHP functions PHP string operations on these, it looks a lot more.
OK. after finishing the above PHP introduction, let's look at the above code and see if it is easy. If you still feel a little dizzy, please forgive me. You can also contact me to improve them. Hey.
Let's continue to explain the above content.
First look at the first line,
Function display_user_urls ($ url_array)
It is used to define a function, because there is a keyword function before, the parameter is a URL array.
Check row 6th, define a global variable $ bm_table, and set it to true.
Behavior
10 <form name = 'bm_table 'action = 'delete_bms.php' method = 'post'>
11 <table width = 300 cellpadding = 2 cellspacing = 0>
It defines a form and contains a table in form. This table is used to display bookmarks. Next, we can see that is used to display the Title of the table. The background color is "# cccccc", and the font is bold. Here you can see
<Tr bgcolor = '$ color'>
$ Color is a variable. in the string operation we mentioned above, how to display a string and the rules for displaying the string -- PHP will try to identify the variable as much as possible, which is embodied here.
Check the judgment statement
16 if (is_array ($ url_array) & count ($ url_array)> 0)
Is_array determines whether $ url_array is an array. Count to obtain the number of $ url_array arrays.
18 lines of code
18 foreach ($ url_array as $ url)
Traverse each value of the array and display it in the Table.
You must note that the htmlspecialchars function is called here to process special HTML characters in user data.
Finally, let's take a look at the effect.