Phát triển web với PHP và MySQL - p 5
Số trang: 10
Loại file: pdf
Dung lượng: 553.37 KB
Lượt xem: 14
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:
PHP Crash Course CHAPTER 115Different tag styles are available. This is the short style. If you have some problems running this script, it might be because short tags are not enabled in your PHP installation. Let’s look at this in more detail.1PHP CRASH COURSEPHP Tag StylesThere are actually four different styles of PHP tags we can use. Each of the following fragments of code is equivalent. • Short styleOrder processed.”; ?This is the tag style that will be used in this book. It is the default tag that PHP developers use to code PHP. This style of tag is the...
Nội dung trích xuất từ tài liệu:
Phát triển web với PHP và MySQL - p 5 PHP Crash Course 15 CHAPTER 1Different tag styles are available. This is the short style. If you have some problems running 1this script, it might be because short tags are not enabled in your PHP installation. Let’s look atthis in more detail. PHP CRASH COURSEPHP Tag StylesThere are actually four different styles of PHP tags we can use. Each of the following frag-ments of code is equivalent. • Short style This is the tag style that will be used in this book. It is the default tag that PHP develop- ers use to code PHP. This style of tag is the simplest and follows the style of an SGML (Standard Generalized Markup Language) processing instruction. To use this type of tag—which is the shortest to type—you either need to enable short tags in your config file, or compile PHP with short tags enabled. You can find more information on how to do this in Appendix A. • XML style This style of tag can be used with XML (Extensible Markup Language) documents. If you plan to serve XML on your site, you should use this style of tag. • SCRIPT style echo “Order processed.”; This style of tag is the longest and will be familiar if you’ve used JavaScript or VBScript. It can be used if you are using an HTML editor that gives you problems with the other tag styles. • ASP style This style of tag is the same as used in Active Server Pages (ASP). It can be used if you have enabled the asp_tags configuration setting. You might want to use this style of tag if you are using an editor that is geared towards ASP or if you already program in ASP.PHP StatementsWe tell the PHP interpreter what to do by having PHP statements between our opening andclosing tags. In this example, we used only one type of statement:echo “Order processed.”; Using PHP16 PART I As you have probably guessed, using the echo construct has a very simple result; it prints (or echoes) the string passed to it to the browser. In Figure 1.2, you can see the result is that the text “Order processed.” appears in the browser window. You will notice that a semicolon appears at the end of the echo statement. This is used to sepa- rate statements in PHP much like a period is used to separate sentences in English. If you have programmed in C or Java before, you will be familiar with using the semicolon in this way. Leaving the semicolon off is a common syntax error that is easily made. However, it’s equally easy to find and to correct. Whitespace Spacing characters such as new lines (carriage returns), spaces and tabs are known as white- space. I would combine the paragraph above and the one below and form one cohesive para- graph explaining how spacing characters (whitespace) is ignored in PHP and HTML. As you probably already know, browsers ignore whitespace in HTML. So does the PHP engine. Consider these two HTML fragments: Welcome to Bob’s Auto Parts!What would you like to order today? and Welcome to Bob’s Auto Parts! What would you like to order today? These two snippets of HTML code produce identical output because they appear the same to the browser. However, you can and are encouraged to use whitespace in your HTML as an aid to humans—to enhance the readability of your HTML code. The same is true for PHP. There is no need to have any whitespace between PHP statements, but it makes the code easier to read if we put each statement on a separate line. For example, echo “hello”; echo “world”; and echo “hello”;echo “world”; are equivalent, but the first version is easier to read. Comments Comments are exactly that: Comments in code act as notes to people reading the code. Comments can be used to explain the purpose of the script, who wrote it, why they wrote it the PHP Crash Course 17 CHAPTER 1way they did, when it was last modified, and so on. You will generally find comments in all 1but the si ...
Nội dung trích xuất từ tài liệu:
Phát triển web với PHP và MySQL - p 5 PHP Crash Course 15 CHAPTER 1Different tag styles are available. This is the short style. If you have some problems running 1this script, it might be because short tags are not enabled in your PHP installation. Let’s look atthis in more detail. PHP CRASH COURSEPHP Tag StylesThere are actually four different styles of PHP tags we can use. Each of the following frag-ments of code is equivalent. • Short style This is the tag style that will be used in this book. It is the default tag that PHP develop- ers use to code PHP. This style of tag is the simplest and follows the style of an SGML (Standard Generalized Markup Language) processing instruction. To use this type of tag—which is the shortest to type—you either need to enable short tags in your config file, or compile PHP with short tags enabled. You can find more information on how to do this in Appendix A. • XML style This style of tag can be used with XML (Extensible Markup Language) documents. If you plan to serve XML on your site, you should use this style of tag. • SCRIPT style echo “Order processed.”; This style of tag is the longest and will be familiar if you’ve used JavaScript or VBScript. It can be used if you are using an HTML editor that gives you problems with the other tag styles. • ASP style This style of tag is the same as used in Active Server Pages (ASP). It can be used if you have enabled the asp_tags configuration setting. You might want to use this style of tag if you are using an editor that is geared towards ASP or if you already program in ASP.PHP StatementsWe tell the PHP interpreter what to do by having PHP statements between our opening andclosing tags. In this example, we used only one type of statement:echo “Order processed.”; Using PHP16 PART I As you have probably guessed, using the echo construct has a very simple result; it prints (or echoes) the string passed to it to the browser. In Figure 1.2, you can see the result is that the text “Order processed.” appears in the browser window. You will notice that a semicolon appears at the end of the echo statement. This is used to sepa- rate statements in PHP much like a period is used to separate sentences in English. If you have programmed in C or Java before, you will be familiar with using the semicolon in this way. Leaving the semicolon off is a common syntax error that is easily made. However, it’s equally easy to find and to correct. Whitespace Spacing characters such as new lines (carriage returns), spaces and tabs are known as white- space. I would combine the paragraph above and the one below and form one cohesive para- graph explaining how spacing characters (whitespace) is ignored in PHP and HTML. As you probably already know, browsers ignore whitespace in HTML. So does the PHP engine. Consider these two HTML fragments: Welcome to Bob’s Auto Parts!What would you like to order today? and Welcome to Bob’s Auto Parts! What would you like to order today? These two snippets of HTML code produce identical output because they appear the same to the browser. However, you can and are encouraged to use whitespace in your HTML as an aid to humans—to enhance the readability of your HTML code. The same is true for PHP. There is no need to have any whitespace between PHP statements, but it makes the code easier to read if we put each statement on a separate line. For example, echo “hello”; echo “world”; and echo “hello”;echo “world”; are equivalent, but the first version is easier to read. Comments Comments are exactly that: Comments in code act as notes to people reading the code. Comments can be used to explain the purpose of the script, who wrote it, why they wrote it the PHP Crash Course 17 CHAPTER 1way they did, when it was last modified, and so on. You will generally find comments in all 1but the si ...
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 phpGợi ý tà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 131 0 0 -
161 trang 129 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 109 1 0 -
MỘT SỐ ĐIỂM CẦN CHÚ Ý KHI THIẾT KẾ WEB
5 trang 108 0 0 -
GIÁO TRÌNH LẬP TRÌNH WEB_PHẦN 2_BÀI 3
3 trang 103 0 0 -
Lập Trình Web: Các trang quản trị trong PHP - GV: Trần Đình Nghĩa
8 trang 94 0 0 -
231 trang 92 1 0
-
101 trang 91 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 65 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 49 0 0