
Professional PHP Programming phần 2
Thông tin tài liệu:
Nội dung trích xuất từ tài liệu:
Professional PHP Programming phần 2Simpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com T o create this JavaScript code dynamically through PHP, we must be careful to escape the backslashes in PHP so that they are passed literally to the JavaScript. For example, consider what happens if we leave the backslashes unescaped: T his is what we would see if we View Source in the browser: T he newlines and tabs were interpreted by PHP instead of being passed as literal characters to JavaScript. This was not our intended effect. We want JavaScript to interpret these symbols as newlines and tabs, not PHP. The code below corrects this problem: TEAM FLY PRESENTSSimpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com B asically, we escape the \ n by typing \ \n . PHP will not interpret it as a newline, but rather as the literal characters \ a nd n . These will be passed on to the browser, where JavaScript will then interpret them as a newline. Similarly, the PHP code \ \t c auses \ t t o be passed to the browser, which is correctly interpreted as a tab by JavaScript. Summary I n the chapter, we learned how PHP interacts with the browser, how it receives HTML form data, and how it dynamically generates HTML documents. Upon submission, HTML form data are converted to name/value pairs and sent to the web server in a URL-encoded query string. URL encoding ensures that reserved characters are safely masked and that name/value pairs are represented in a standard way. PHP receives the data in the form of variables. URL encoding can also be used to pass variables from one PHP script to another. PHP provides three notations for comments: ❑ // Comment ❑ # Comment /* ❑ Comment */ T he first two of the comment types are used to comment single lines. The third type of comment code can be used to comment blocks of multiple lines. The backslash (\ ) is used to e scape a c haracter. Characters are often escaped to indicate a literal depiction of the character: e cho (The variable \$applicant equals $applicant.); S ome escape sequences have special meanings, such as \ n (newline) and \t ( tab). TEAM FLY PRESENTSSimpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 4 1 Variables, Constants , and Data Types I n the previous chapter, we met PHP variables and saw briefly how to use them. We stated that PHP variables must begin with the dollar character ( $ ) and that PHP is a weakly-typed language – that is, variables can contain any type of data and do not have to be predefined as strings, integers, etc. We also saw how we can use PHP variables to extract data from an HTML form. In this chapter, we will look in more detail at variables and their data types. We will consider the issue of data type juggling in more detail, and we will look at some of the functions we can use to manipulate variables. We will also see how to assign a name to a constant value, which remains the same throughout the program. Data Types P HP has three basic data types: integer, double and string. There are also some not-so-basic types, namely arrays and objects, which are discussed in later chapters. Every variable has a specific type, though, as we’ve already mentioned, a variable’s type may change on the fly as the variable’s value changes, or as the code otherwise dictates. Integers use four bytes of memory and are used to represent ordinary, non-decimal numbers in the range of approximately –2 billion to +2 billion. Doubles, also known as float (floating-point) or real numbers, are used to represent numbers that contain a decimal value or an exponent. Strings are used to represent non- numeric values, like letters, punctuation marks, and even numerals. 2 // This is an integer 1 [JHS] Ive added a bit of an introduction to avoid the abrupt start to the chapter. The chapter seems technically accurate, but I think we could do with a bit more explantion in places. The major topic which is omitted from this chapter is HTTP environment variables. We need a large section on these. While a complete listing should form an appendix, we need to show in this chapter how to access HTTP variables from PHP and to give a couple of practical examples: it would be good if these could be incorporated into the Job Application Form. TEAM FLY PRESENTSSimpo PDF Merge and Split Unregistered Version - http://www.simpopdf.com 2.0 // This is a double 2 // This is a string 2 hours // This is another string M any languages contain a Boolean data type to represent the logical values T RUE a nd F ALSE . PHP does not. It instead uses expressions of the other three basic types tha ...
Tìm kiếm theo từ khóa liên quan:
lập trình windows ứng dụng windows tìm hiểu windows lập trình ứng dụng lập trình phần mềm lập trình hệ thống lập trình dotNet lập trình Java lập trình PHPTài liệu có liên quan:
-
Mô tả công việc lập trình viên phần mềm
1 trang 230 0 0 -
Bài tập lập trình Windows dùng C# - Bài thực hành
13 trang 204 0 0 -
Bài giảng Công nghệ phần mềm - Chương 2: Quy trình xây dựng phần mềm
36 trang 185 0 0 -
Đề cương môn học Phân tích thiết kế phần mềm
143 trang 180 0 0 -
bảo mật mạng các phương thức giả mạo địa chỉ IP fake IP
13 trang 169 0 0 -
Luận văn : Xây dựng chương trình sắp xếp lịch trực bác sĩ
61 trang 162 0 0 -
Luận văn: Nghiên cứu kỹ thuật giấu tin trong ảnh Gif
33 trang 159 0 0 -
Đồ án tốt nghiệp: Bảng LED ma trận điều khiển bằng ứng dụng Android
102 trang 149 0 0 -
Giáo trình Lập trình Android cơ bản: Phần 1
190 trang 139 0 0 -
[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 137 0 0 -
Excel add in development in c and c phần 9
0 trang 124 0 0 -
information technology outsourcing transactions process strategies and contracts 2nd ed phần 3
65 trang 116 0 0 -
LUẬN VĂN: Tìm hiểu kỹ thuật tạo bóng cứng trong đồ họa 3D
41 trang 115 0 0 -
Program C Ansi Programming Embedded Systems in C and C++ phần 4
12 trang 103 0 0 -
Giáo trình Lập trình Windows 1 - Trường CĐN Đà Lạt
117 trang 103 0 0 -
Giáo trình môn kỹ thuật vi điều khiển
0 trang 100 0 0 -
Bài thu hoạch cá nhân môn Quản trị dự án phần mềm
75 trang 97 0 0 -
265 trang 92 0 0
-
81 trang 92 0 0
-
Bài giảng Lập trình trên Windows: Chương 1 - Trần Minh Thái
68 trang 90 0 0