By no means could this appendix replace the value of the PHP manual, but the tables and information listed here might save you a trip online to view it. In this section you'll find lists of Operators, comparators, and their precedence Date- and time-formatting parameters and functions Regular expression characters and classes And more! Operators and comparators Many of PHP's operators and comparators (symbols used to make comparisons) are self-evident. Still, to be explicit, I've listed most of them in Table B.1. Along with these, don't forget about the variations on the assignment operators: .=, +=, -=, *=, and /=. Table B.1. PHP's characters for performing operations or making comparisons.PHP Operators |
---|
SYMBOL | MEANING | TYPE |
---|
= | is assigned the value of | assignment | ==- | is equal to | comparison | != | is not equal to | comparison | < | less than | comparison | > | greater than | comparison | <= | less than or equal to | comparison | >= | greater than or equal to | comparison | ! | is not | logical | && | and | logical | and | and | logical | || | or | logical | or | or | logical | xor | or not | logical | + | addition | arithmetic | - | subtraction | arithmetic | * | multiplication | arithmetic | / | division | arithmetic | % | modulus | arithmetic | . | concatenation | miscellaneous | ++ | increment by 1 | arithmetic | -- | decrement by 1 | arithmetic |
Table B.2 places most of Table B.1 in order of precedence, from highest (at the top) to lowest. You can memorize this list when writing complex statements or use parentheses to always guarantee the order in which operators will be evaluated. Table B.2. The precedence given to PHP's operators and comparators, from most important (at the top) to least.Operator Precedence |
---|
OPERATOR |
---|
! ++ -- | * / % | + -. | < <= > >= | == != === | && | || | = += -= *= /= .= %= | and | xor |
Date and time After years of programming in PHP, what I still frequently must look up are the formatting parameters used with the date() function. I have recorded most of these in Table B.3. You'll find them in year, month, day, hour, minute, second order, since listing them alphabetically makes it harder to find the formatting you want (check the manual for comparison). Table B.3. These are the formatting parameters to use with the date() function.Date() Function Formatting |
---|
CHARACTER | MEANING | EXAMPLE |
---|
Y | year as 4 digits | 2005 | y | year as 2 digits | 05 | n | month as 1 or 2 digits | 2 | m | month as 2 digits | 02 | F | month | February | M | month as 3 letters | Feb | j | day of the month as 1 or 2 digits | 8 | d | day of the month as 2 digits | 08 | l (lowercase L) | day of the week | Monday | D | day of the week as 3 letters | Mon | w | day of the week as a single digit | 0 (Sunday) | z | day of the year: 0 to 365 | | t | number of days in the given month | 31 | g | hour, 12-hour format as 1 or 2 digits | 6 | G | hour, 24-hour format as 1 or 2 digits | 18 | h | hour, 12-hour format as 2 digits | 06 | H | hour, 24-hour format as 2 digits | 18 | i | minutes | 45 | s | seconds | 18 | a | am or pm | am | A | AM or PM | PM |
As a reminder, the syntax for using the date function is date (format, timestamp) The function takes the format as a quoted string and can also take an optional timestamp (as an integer). The date() function will return a string value. For example, echo date ("F j, Y"); // May 3, 2005 The geTDate() function, discussed in Chapter 3, "Creating Dynamic Web Sites," returns an array of information for a particular date. The keys and values stored in the array are displayed in Table B.4. $date_array = getdate(); Table B.4. The array returned by the getdate() function.The getdate() Array |
---|
KEY | MEANING | EXAMPLE |
---|
year | year | 2005 | mon | month | 12 | month | month name | December | mday | day of the month | 25 | weekday | day of the week | Tuesday | hours | hours | 11 | minutes | minutes | 56 | seconds | seconds | 47 |
This function also takes an optional timestamp. Regular expressions In Chapter 10, "Web Application Security," I discussed regular expressions as a means to validate user-submitted form data. Here is a repeat of the three tables listed in that section, with some minor alterations (Tables B.5, B.6, and B.7). These characters are used to establish patterns that will be matched using the ereg(), eregi(), ereg_replace(), and eregi_replace() functions. Table B.5. These characters have special meanings for regular expressions, although not within classes.Metacharacters |
---|
CHARACTER | MEANING |
---|
^ | Indicates the beginning of a string | $ | Indicates the end of a string | . | Any single character | | | Alternatives (or) | \ | Escapes the following character | () | Used for making groups | [] | Used for defining classes |
Table B.6. Use these symbols to specify quantities in your regular expressions.Quantifiers |
---|
CHARACTER | MEANING |
---|
? | 0 or 1 | * | 0 or more | + | 1 or more | {x} | exactly x occurrences | {x, y} | between x and y (inclusive) | {x,} | at least x occurrences |
Table B.7. These classes are shorthand for common character sets.Character Classes |
---|
CLASS | MEANING |
---|
[a-z] | Any lowercase letter | [a-zA-Z] | Any letter | [0-9] | Any number | [ \f\r\t\n\v] | Any white space | [aeiou] | Any vowel | [[:alnum:]] | Any letter or number | [[:alpha:]] | Any letter (same as [a-zA-Z]) | [[:blank:]] | Any tabs or spaces | [[:digit:]] | Any number (same as [0-9]) | [[:lower:]] | Any lowercase letter | [[:upper:]] | Any uppercase letter | [[:punct:]] | Punctuation characters (.,;:-) | [[:space:]] | Any white space |
Other references The last set of PHP references I'll include are a grab bag of ideas discussed throughout the book. Table B.8 lists the key-value pairs returned by the getimagesize() function. The most frequently used value is indexed at 3, which is a string used to create the HTML code for the height and width of the image. The third element in the array is a numeric representation of the image type where 1 means GIF, 2 is JPG, 3 PNG, 4 SWF (Shockwave Format), 5 PSD (Photoshop), 6 BMP (Bitmap), 7 and 8, TIFF (two different types), and so on. Table B.8. The getimagesize() function returns an array with these keys and values.The getimagesize() Array |
---|
ELEMENT | VALUE | EXAMPLE |
---|
0 | image's width in pixels | 423 | 1 | image's height in pixels | 368 | 2 | image's type | 2 (representing JPG) | 3 | appropriate HTML img data | height="xx" width="yy" |
Finally, Table B.9 displays the contents of the $_FILES array, used when uploading files through the Web browser. Table B.9. When uploading files, use the $_FILES array to access them.The $_FILES Array |
---|
INDEX | MEANING |
---|
name | The original name of the file (as it was on the user's computer) | type | The MIME type of the file, as provided by the browser | size | The size of the uploaded file in bytes | tmp_name | The temporary filename of the uploaded file as it was stored on the server | error | The error code associated with anyproblem in uploading |
|