1. Trang chủ
  2. » Công Nghệ Thông Tin

PHP Developer''''s Dictionary- P16 potx

5 314 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 362,17 KB

Nội dung

PHP Developer’s Dictionary IT-SC book 75 require(string filename) Description The require() language construct, which is similar to the Server Side Include (SSI) #include directive, enables you to include other files specified by filename . These secondary files can be valid PHP code or any text, such as HTML. If you do have additional PHP code that needs to be executed, be sure that you use the proper beginning and ending PHP tags or the parser will not execute the code. The difference between this and include() is that include() calls are executed each time they are encountered, whereas require() pulls in the contents of the included file always and only once. This means it will pull in the file even if it is not executed (such as in the body of an if statement that did not pass its condition). This is unlike include(), which pulls in the file only when executed. Note PHP3 enabled programmers to execute return statements in the included file, but PHP4 has deprecated that feature, so avoid using it. switch case Syntax switch(variable){ case value1: code [break;] case value2: code [break;] case valueN: code [break;] [ default: code] } Description The switch case statement has an effect similar to that of multiple if statements. For variable , the statement will look at each case ( value1 , value2 , , valueN ) to determine where variable is equal. When a match is found, code under that case PHP Developer’s Dictionary IT-SC book 76 is executed. If you want to break out of the statement completely after you have found a match, you need to include the optional break command; otherwise, every portion of code will be executed—not just the code under the case it matched. If you want to include a default value in case of no matches, include the default section. The code under this section will be executed if none of the previous case statements match. switch : endswitch Syntax switch(variable): case value1: code [break;] case value2: code [break;] case valueN: code [break;] [ default: code] endswitch; Description The switch : endswitch statement is an alternative syntax for the switch case loop. Using this method, the opening and closing braces are replaced with : and endswitch , respectively. See the switch case entry for more information on variable , value (s), and code . switch($num): case 0: echo "The number is 0"; break; case 1: echo "The number is 1"; break; default: echo "The number is not 0 or 1"; endswitch; while Syntax PHP Developer’s Dictionary IT-SC book 77 while(condition){ code } Description The while loop evaluates the condition and if it evaluates to true, executes code . This will continue until condition no longer evaluates to true. This loop is similar to the do while loop except that it is not guaranteed to execute at least once, whereas the do while loop is. while: endwhile Syntax while(condition): code endwhile; Description The while : endwhile statement is an alternative syntax for the while loop. Using this method, the opening and closing braces are replaced with : and endwhile , respectively. See the while entry for more information on condition and code . Escape Characters Escape characters are signified by a \ before one of several reserved characters that signify noncharacter data, such as a tab or space. These characters are often used when parsing through strings or outputting text that requires these characters. \n Syntax \n Description The \n escape character represents a newline character. This is often thought of as the character entered when pressing the Return or Enter key on your keyboard. \r PHP Developer’s Dictionary IT-SC book 78 Syntax \r Description The \r escape character represents a carriage return. In the Macintosh world, this is the character entered when pressing the Return or Enter key on your keyboard. \t Syntax \t Description The \t escape character is used to represent the entry of a tab. \ \ Syntax \\ Description The \\ escape character does not escape a non-character–based entry, but rather is used to represent a backslash, "\ ". This is necessary only because the backslash is a reserved character in the PHP language and must be escaped when you are literally referring to that character. \$ Syntax \$ Description PHP Developer’s Dictionary IT-SC book 79 The \$ escape character is used to represent the dollar sign. \" Syntax \" Description The \" escape character does not escape a non-character–based entry, but rather is used to represent a double quotation mark ("). \[0-7]{1,3} Syntax \[0-7]{1,3} Description The \[0-7]{ 1,3} syntax specifies that the sequence of characters matching the regular expression is a character in octal notation that contains one or three characters (defined by the { 1,3}).([0-7]) the regular expression is a character in octal notation that contains one or three characters (defined by the {1,3} ). \x[0-9A-Fa-f]{1,2} Syntax \ x[0-9A-Fa-f]{ 1,2} Description The \ x[0-9A-Fa-f]{ 1,2} syntax specifies that the sequence of characters matching ( [0-9A-Fa-f] ) the regular expression is a character in hexadecimal notation that contains one or two characters (defined by the {1,2} ). Objects and Functions . files can be valid PHP code or any text, such as HTML. If you do have additional PHP code that needs to be executed, be sure that you use the proper beginning and ending PHP tags or the parser. include(), which pulls in the file only when executed. Note PHP3 enabled programmers to execute return statements in the included file, but PHP4 has deprecated that feature, so avoid using it. . backslash is a reserved character in the PHP language and must be escaped when you are literally referring to that character. $ Syntax $ Description PHP Developer’s Dictionary IT-SC book

Ngày đăng: 07/07/2014, 05:20

TỪ KHÓA LIÊN QUAN