![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 8
Số trang: 10
Loại file: pdf
Dung lượng: 603.49 KB
Lượt xem: 9
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 SCRIPTSCombining calculations and assignmentPHP offers a shorthand way of performing a calculation on a variable and reassigning the result to the variable through combined assignment operators. The main ones are listed in Table 3-3. Table 3-3. Combined arithmetic assignment operators used in PHP Operator += -= *= /= %= Example $a += $b $a -= $b $a *= $b $a /= $b $a %= $b Equivalent to $a = $a + $b $a = $a - $b $a = $a * $b $a = $a / $b $a = $a % $bAdding to an existing stringThe...
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 8 HOW TO WRITE PHP SCRIPTSCombining calculations and assignment PHP offers a shorthand way of performing a calculation on a variable and reassigning the result to the variable through combined assignment operators. The main ones are listed in Table 3-3. Table 3-3. Combined arithmetic assignment operators used in PHP Operator Example Equivalent to += $a += $b $a = $a + $b -= $a -= $b $a = $a - $b *= $a *= $b $a = $a * $b /= $a /= $b $a = $a / $b %= $a %= $b $a = $a % $bAdding to an existing string The same convenient shorthand allows you to add new material to the end of an existing string by combining a period and an equal sign, like this: $hamlet = To be; $hamlet .= or not to be; Note that you need to create a space at the beginning of the additional text unless you want both strings to run on without a break. This shorthand, known as the combined concatenation operator, is extremely useful when combining many strings, such as you need to do when building the content of an email message or looping through the results of a database search. The period in front of the equal sign is easily overlooked when copying code. When you see the same variable repeated at the beginning of a series of statements, it s often a sure sign that you need to use .= instead of = on its own.All you ever wanted to know about quotes—and more Handling quotes within any computer language—not just PHP—can be fraught with difficulties because computers always take the first matching quote as marking the end of a string. Structured Query Language (SQL)—the language used to communicate with databases—also uses strings. Since your strings may include apostrophes, the combination of single and double quotes isn t enough. Moreover, PHP gives variables and escape sequences (certain characters preceded by a backslash) special treatment inside double quotes. Over the next few pages, I ll unravel this maze and make sense of it all for you. 51 CHAPTER 3 How PHP treats variables inside strings Choosing whether to use double quotes or single quotes might just seem like a question of personal preference, but there s an important difference in the way that PHP handles them. • Anything between single quotes is treated literally as text. • Double quotes act as a signal to process variables and special characters known as escape sequences. Take a look at the following examples to see what this means. In the first example (the code is in quotes1.php), $name is assigned a value and then used in a single-quoted string. As you can see from the screenshot alongside the code, $name is treated like normal text. $name = Dolly; // Single quotes: $name is treated as literal text echo Hello, $name; If you replace the single quotes in the final line with double ones (see quotes2.php), $name is processedDownload from Wow! eBook and its value is displayed onscreen. $name = Dolly; // Double quotes: $name is processed echo Hello, $name; In both examples, the string in the first line is in single quotes. What causes the variable to be processed is the fact that it s in a double-quoted string, not how it originally got its value. Because double quotes are so useful in this way, many people use them all the time. Technically speaking, using double quotes when you don t need to process any variables is inefficient. My preference ...
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 8 HOW TO WRITE PHP SCRIPTSCombining calculations and assignment PHP offers a shorthand way of performing a calculation on a variable and reassigning the result to the variable through combined assignment operators. The main ones are listed in Table 3-3. Table 3-3. Combined arithmetic assignment operators used in PHP Operator Example Equivalent to += $a += $b $a = $a + $b -= $a -= $b $a = $a - $b *= $a *= $b $a = $a * $b /= $a /= $b $a = $a / $b %= $a %= $b $a = $a % $bAdding to an existing string The same convenient shorthand allows you to add new material to the end of an existing string by combining a period and an equal sign, like this: $hamlet = To be; $hamlet .= or not to be; Note that you need to create a space at the beginning of the additional text unless you want both strings to run on without a break. This shorthand, known as the combined concatenation operator, is extremely useful when combining many strings, such as you need to do when building the content of an email message or looping through the results of a database search. The period in front of the equal sign is easily overlooked when copying code. When you see the same variable repeated at the beginning of a series of statements, it s often a sure sign that you need to use .= instead of = on its own.All you ever wanted to know about quotes—and more Handling quotes within any computer language—not just PHP—can be fraught with difficulties because computers always take the first matching quote as marking the end of a string. Structured Query Language (SQL)—the language used to communicate with databases—also uses strings. Since your strings may include apostrophes, the combination of single and double quotes isn t enough. Moreover, PHP gives variables and escape sequences (certain characters preceded by a backslash) special treatment inside double quotes. Over the next few pages, I ll unravel this maze and make sense of it all for you. 51 CHAPTER 3 How PHP treats variables inside strings Choosing whether to use double quotes or single quotes might just seem like a question of personal preference, but there s an important difference in the way that PHP handles them. • Anything between single quotes is treated literally as text. • Double quotes act as a signal to process variables and special characters known as escape sequences. Take a look at the following examples to see what this means. In the first example (the code is in quotes1.php), $name is assigned a value and then used in a single-quoted string. As you can see from the screenshot alongside the code, $name is treated like normal text. $name = Dolly; // Single quotes: $name is treated as literal text echo Hello, $name; If you replace the single quotes in the final line with double ones (see quotes2.php), $name is processedDownload from Wow! eBook and its value is displayed onscreen. $name = Dolly; // Double quotes: $name is processed echo Hello, $name; In both examples, the string in the first line is in single quotes. What causes the variable to be processed is the fact that it s in a double-quoted string, not how it originally got its value. Because double quotes are so useful in this way, many people use them all the time. Technically speaking, using double quotes when you don t need to process any variables is inefficient. My preference ...
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