SakhaliaNetHome PageMilitary HistoryVorKutaAcceptance of cookiesAcceptance of cookies

PHP Tutorial :: Reference (I)

Reference of PHP

Special characters for double quoted strings

\n (Break line)

\r (Carriage return)

\t (Tabulation)

\\ (Allows to include a backslash symbol in the string)

\$ (Allows to include a $ symbol in the string)

\" (Allows to include a double quote symbol in the string)

\0 to \777 (Octal numbers)

\x0 to \xFF (Hexadecimal numbers)

Reference of PHP

Special characters for text format

Formatting rules start by % and are followed by some optional modifiers:

A filling character: If the string that pretends to replace the format rule is too short, this character will be used to fill it. You can type a space to fill with spaces or a 0 to fill with zeros.

A sign: For numbers, a sign + forces printf() to print the sign + before positive numbers (by default they are print without any sign). For strings, a sign - forces printf() to align the string to the right (by default it is aligned to the left).

A minimum width: The minimum size that should have the value that replaces the format string; if it is shorter, the filling character will be used to complete the string.

A point and a precision number: For float numbers it controls how many digits appear after the decimal point.

After the optional modifiers a mandatory character has to be placed, to indicate the type of value that will be printed. Most habitual values are b (integer as binary), c (integer as ASCII), d (integer with sign), e (scientific notation), f (float number), o (integer as octal number), s (string), x (integer as hexadecimal number) and u (integer without sign).

Example: %.2f is a simple format rule for a float number with two decimals.

Reference of PHP

Operators

= (allocation)

+ (addition)

- (substraction)

* (multiplication)

/ (division)

% (modulus)

++ (increment by 1)

-- (decrement by 1)

+= (increment by a subsequent value)

-= (decrement by a subsequent value)

*= (multiplication by a subsequent value)

/= (division by a subsequent value)

%= (modulus by a subsequent value)

. (concatenate)

.= (concatenate to a subsequent string)

== (equal than)

=== (identical than)

!= (not equal than)

> (greater than)

< (lesser than)

>= (greater or equal than)

<= (lesser or equal than)

! (not)

&& (AND)

|| (OR)

Reference of PHP

Server variables

These variables belong to the auto-global array $_SERVER[].

QUERY_STRING (example: category=kitchen&price=5) The part of the URL after the interrogation sign where the URL parameter lies. The example could be for http://www.example.com/catalog/store.php?category=kitchen&price=5.

PATH_INFO (example: /browse) Additional information of access path located at the end of an URL after a slash symbol. It is a way to pass information to a script without using the query string. The example could be for http://www.example.com/catalog/store.php/browse.

SERVER_NAME (example: www.example.com) The name of the web server where the PHP interpreter is executed. If the server hosts different virtual domains, this is the name of the virtual domain that is being accessed in particular.

DOCUMENT_ROOT (example: /usr/local/htdocs) The directory in the web server that contains the documents available in the website. /usr/local/htdocs/ would be the equivalent to http://www.example.com/.

REMOTE_ADDR (example: 175.56.28.3) The IP address of the user that performs a petition to the web server.

REMOTE_HOST (example: pool0560.cvx.dialup.verizon.net) If the server is configured to translate IP addresses of users into host names, this will be the name of the user that performs a petition to the web server.

HTTP_REFERER (example: http://directory.google.com/Top/Shopping/Clothing) If someone did click on a link to arrive to the active URL, HTTP_REFERER will contain the URL of the page that contains such link. This value can be faked, so it shouldn't be used as a proper criterion to facilitate access to private areas. However, it can be useful to know who is setting links with us.

HTTP_USER_AGENT (example: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)) The web browser that access the page. This value can be faked as well, but it is still useful for analytics.