![Phân tích tư tưởng của nhân dân qua đoạn thơ: Những người vợ nhớ chồng… Những cuộc đời đã hóa sông núi ta trong Đất nước của Nguyễn Khoa Điềm](https://timtailieu.net/upload/document/136415/phan-tich-tu-tuong-cua-nhan-dan-qua-doan-tho-039-039-nhung-nguoi-vo-nho-chong-nhung-cuoc-doi-da-hoa-song-nui-ta-039-039-trong-dat-nuoc-cua-nguyen-khoa-136415.jpg)
Giải pháp thiết kế web động với PHP - p 7
Số trang: 10
Loại file: pdf
Dung lượng: 526.28 KB
Lượt xem: 10
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
HOW TO WRITE PHP SCRIPTS} elseif ( second condition is true ) { // code to be executed if first condition fails // but second condition is true } else { // default code if both conditions are false } You can use as many elseif clauses in a conditional statement as you like. It s important to note that only the first one that equates to true will be executed; all others will be ignored, even if they re also true. This means you need to build conditional statements in the order of priority that you want them to...
Nội dung trích xuất từ tài liệu:
Giải pháp thiết kế web động với PHP - p 7 HOW TO WRITE PHP SCRIPTS } elseif ( second condition is true ) { // code to be executed if first condition fails // but second condition is true } else { // default code if both conditions are false } You can use as many elseif clauses in a conditional statement as you like. It s important to note that only the first one that equates to true will be executed; all others will be ignored, even if they re also true. This means you need to build conditional statements in the order of priority that you want them to be evaluated. It s strictly a first-come, first-served hierarchy. Although elseif is normally written as one word, you can use else if as separate words. An alternative decision-making structure, the switch statement, is described in the second half of this chapter.Making comparisons Conditional statements are interested in only one thing: whether the condition being tested equates to true. If it s not true, it must be false. There s no room for half-measures or maybes. Conditions often depend on the comparison of two values. Is this bigger than that? Are they both the same? And so on. To test for equality, PHP uses two equal signs (==) like this: if ($status == administrator) { // send to admin page } else { // refuse entry to admin area } Don t use a single equal sign in the first line ( $status = administrator ). Doing so will open the admin area of your website to everyone. Why? Because this automatically sets the value of $status to administrator ; it doesn t compare the two values. To compare values, you must use two equal signs. It s an easy mistake to make, but one with potentially disastrous consequences. Size comparisons are performed using the mathematical symbols for less than (). Let s say you re checking the size of a file before allowing it to be uploaded to your server. You could set a maximum size of 50kB like this (1 kilobyte = 1024 bytes): if ($bytes > 51200) { // display error message and abandon upload } else { // continue upload } You can test for multiple conditions simultaneously. Details are in the second half of this chapter. 41 CHAPTER 3 Using indenting and whitespace for clarity Indenting code helps to keep statements in logical groups, making it easier to understand the flow of the script. There are no fixed rules; PHP ignores any whitespace inside code, so you can adopt any style you like. The important thing is to be consistent so that you can spot anything that looks out of place. The limited width of the printed page means that I normally use just two spaces to indent code in this book, but most people find that tabbing four or five spaces makes for the most readable code. Perhaps the biggest difference in styles lies in the way individual developers arrange curly braces. I put the opening curly brace of a code block on the same line as the preceding code, and put the closing brace on a new line after the code block, like this: if ($bytes > 51200) { // display error message and abandon upload } else { // continue upload } However, others prefer this style: if ($bytes > 51200)Download from Wow! eBook { // display error message and abandon upload } else { // continue upload } The style isn t important. What matters is that your code is consistent and easy to read. Using loops for repetitive tasks Loops are hug ...
Nội dung trích xuất từ tài liệu:
Giải pháp thiết kế web động với PHP - p 7 HOW TO WRITE PHP SCRIPTS } elseif ( second condition is true ) { // code to be executed if first condition fails // but second condition is true } else { // default code if both conditions are false } You can use as many elseif clauses in a conditional statement as you like. It s important to note that only the first one that equates to true will be executed; all others will be ignored, even if they re also true. This means you need to build conditional statements in the order of priority that you want them to be evaluated. It s strictly a first-come, first-served hierarchy. Although elseif is normally written as one word, you can use else if as separate words. An alternative decision-making structure, the switch statement, is described in the second half of this chapter.Making comparisons Conditional statements are interested in only one thing: whether the condition being tested equates to true. If it s not true, it must be false. There s no room for half-measures or maybes. Conditions often depend on the comparison of two values. Is this bigger than that? Are they both the same? And so on. To test for equality, PHP uses two equal signs (==) like this: if ($status == administrator) { // send to admin page } else { // refuse entry to admin area } Don t use a single equal sign in the first line ( $status = administrator ). Doing so will open the admin area of your website to everyone. Why? Because this automatically sets the value of $status to administrator ; it doesn t compare the two values. To compare values, you must use two equal signs. It s an easy mistake to make, but one with potentially disastrous consequences. Size comparisons are performed using the mathematical symbols for less than (). Let s say you re checking the size of a file before allowing it to be uploaded to your server. You could set a maximum size of 50kB like this (1 kilobyte = 1024 bytes): if ($bytes > 51200) { // display error message and abandon upload } else { // continue upload } You can test for multiple conditions simultaneously. Details are in the second half of this chapter. 41 CHAPTER 3 Using indenting and whitespace for clarity Indenting code helps to keep statements in logical groups, making it easier to understand the flow of the script. There are no fixed rules; PHP ignores any whitespace inside code, so you can adopt any style you like. The important thing is to be consistent so that you can spot anything that looks out of place. The limited width of the printed page means that I normally use just two spaces to indent code in this book, but most people find that tabbing four or five spaces makes for the most readable code. Perhaps the biggest difference in styles lies in the way individual developers arrange curly braces. I put the opening curly brace of a code block on the same line as the preceding code, and put the closing brace on a new line after the code block, like this: if ($bytes > 51200) { // display error message and abandon upload } else { // continue upload } However, others prefer this style: if ($bytes > 51200)Download from Wow! eBook { // display error message and abandon upload } else { // continue upload } The style isn t important. What matters is that your code is consistent and easy to read. Using loops for repetitive tasks Loops are hug ...
Tìm kiếm theo từ khóa liên quan:
lập trình web giáo trình php thiết kế web với php tự học php lập trình phpTài liệu liên quan:
-
[Thảo luận] Học PHP như thế nào khi bạn chưa biết gì về lập trình?
5 trang 134 0 0 -
161 trang 134 1 0
-
Bài giảng Lập trình web nâng cao: Chương 8 - Trường ĐH Văn Hiến
36 trang 121 1 0 -
MỘT SỐ ĐIỂM CẦN CHÚ Ý KHI THIẾT KẾ WEB
5 trang 116 0 0 -
GIÁO TRÌNH LẬP TRÌNH WEB_PHẦN 2_BÀI 3
3 trang 105 0 0 -
Lập Trình Web: Các trang quản trị trong PHP - GV: Trần Đình Nghĩa
8 trang 105 0 0 -
231 trang 95 1 0
-
101 trang 94 2 0
-
Bài giảng Lập trình web nâng cao: Chương 7 - Trường ĐH Văn Hiến
16 trang 66 1 0 -
Bài giảng Lập trình Web ASP.Net với C#: Chương 9 - Th.S Phạm Đào Minh Vũ
55 trang 52 0 0