key |
mixed key(array array) |
Returns the key for the element currently pointed to by the internal array pointer.
key_exists |
bool key_exists(mixed key, array array) |
Returns true if array contains a key with the value key. If no such key is available, returns false.
krsort |
int krsort(array array[, int flags]) |
Sorts an array by key in reverse order, maintaining the keys for the array values. The optional second parameter contains additional sorting flags. See Chapter 5 and sort for more information on using this function.
ksort |
int ksort(array array[, int flags]) |
Sorts an array by key, maintaining the keys for the array values. The optional second parameter contains additional sorting flags. See Chapter 5 and sort for more information on using this function.
lcg_value |
double lcg_value( ) |
Returns a pseudorandom number between 0 and 1, inclusive, using a linear congruential- number generator.
levenshtein |
int levenshtein(string one, string two[, int insert, int replace, int delete]) int levenshtein(string one, string two[, mixed callback]) |
Calculates the Levenshtein distance between two strings; this is the number of characters you have to replace, insert, or delete to transform one into two. By default, replacements, inserts, and deletes have the same cost, but you can specify different costs with insert, replace, and delete. In the second form, you provide a callback to calculate the cost of an operation.
link |
int link(string path, string new) |
Creates a hard link to path at the path new. Returns true if the link was successfully created and false if not.
linkinfo |
int linkinfo(string path) |
Returns true if path is a link and if the file referenced by path exists. Returns false if path is not a link, if the file referenced by it does not exist, or if an error occurs.
list |
void list(mixed value1[, ... valueN]) |
Assigns a set of variables from elements in an array. For example:
list($first, $second) = array(1, 2); // $first = 1, $second = 2
Note: list is actually a language construct.
localeconv |
array localeconv( ) |
Returns an associative array of information about the current locale's numeric and monetary formatting. The array contains the following elements:
decimal_point |
Decimal-point character |
thousands_sep |
Separator character for thousands |
grouping |
Array of numeric groupings; indicates where the number should be separated using the thousands separator character |
int_curr_symbol |
International currency symbol (e.g., "USD") |
currency_symbol |
Local currency symbol (e.g., "$") |
mon_decimal_point |
Decimal-point character for monetary values |
mon_thousands_sep |
Separator character for thousands in monetary values |
positive_sign |
Sign for positive values |
negative_sign |
Sign for negative values |
int_frac_digits |
International fractional digits |
frac_digits |
Local fractional digits |
p_cs_precedes |
true if the local currency symbol precedes a positive value; false if it follows the value |
p_sep_by_space |
true if a space separates the local currency symbol from a positive value |
p_sign_posn |
0 if parentheses surround the value and currency symbol for positive values, 1 if the sign precedes the currency symbol and value, 2 if the sign follows the currency symbol and value, 3 if the sign precedes the currency symbol, and 4 if the sign follows the currency symbol |
n_cs_precedes |
true if the local currency symbol precedes a negative value; false if it follows the value |
n_sep_by_space |
true if a space separates the local currency symbol from a negative value |
n_sign_posn |
0 if parentheses surround the value and currency symbol for negative values, 1 if the sign precedes the currency symbol and value, 2 if the sign follows the currency symbol and value, 3 if the sign precedes the currency symbol, and 4 if the sign follows the currency symbol |
localtime |
array localtime([int timestamp[, bool associative]) |
Returns an array of values as given by the C function of the same name. The first argument is the timestamp; if the second argument is provided and is true, the values are returned as an associative array. If the second argument is not provided or is false, a numeric array is returned. The keys and values returned are:
tm_sec |
Seconds |
tm_min |
Minutes |
tm_hour |
Hour |
tm_mday |
Day of the month |
tm_mon |
Month of the year |
tm_year |
Number of years since 1900 |
tm_wday |
Day of the week |
tm_yday |
Day of the year |
tm_isdst |
1 if Daylight Savings Time was in effect at the date and time |
If a numeric array is returned, the values are in the order given above.
lstat |
array lstat(string path) |
Returns an associative array of information about the file path. If path is a symbolic link, information about path is returned, rather than information about the file to which path points. See fstat for a list of the values returned and their meanings.
ltrim |
string ltrim(string string[, string characters]) |
Returns string with all characters in characters stripped from the beginning. If characters is not specified, the characters stripped are \n, \r, \t, \v, \0, and spaces.
bool mail(string recipient, string subject, string message[, string headers [, string parameters]]) |
Sends message to recipient via email with the subject subject and returns true if the message was successfully sent or false if it wasn't. If given, headers is added to the end of the headers generated for the message, allowing you to add cc:, bcc:, and other headers. To add multiple headers, separate them with \n characters (or \r\n characters on Windows servers). Finally, if specified, parameters is added to the parameters of the call to the mailer program used to send the mail.
max |
mixed max(mixed value1[, mixed value2[, ... mixed valueN]]) |
If value1 is an array, returns the largest number found in the values of the array. If not, returns the largest number found in the arguments.
metaphone |
string metaphone(string string, int max_phonemes) |
Calculates the metaphone key for string. The maximum number of phonemes to use in calculating the value is given in max_phonemes. Similar-sounding English words generate the same key.
method_exists |
bool method_exists(object object, string name) |
Returns true if the object contains a method with the name given in the second parameter or false otherwise. The method may be defined in the class of which the object is an instance, or in any superclass of that class.
microtime |
string microtime( ) |
Returns a string in the format "microseconds seconds", where seconds is the number of seconds since the Unix epoch, and microseconds is the microseconds portion of the time since the Unix epoch.
min |
mixed min(mixed value1[, mixed value2[, ... mixed valueN]]) |
If value1 is an array, returns the smallest number found in the values of the array. If not, returns the smallest number found in the arguments.
mkdir |
int mkdir(string path, int mode) |
Creates the directory path with mode permissions. The mode is expected to be an octal number, such as 0755. An integer value such as 755 or a string value such as "u+x" will not work as expected. Returns true if the operation was successful and false if not.
mktime |
int mktime(int hours, int minutes, int seconds, int month, int day, int year [, int is_dst]) |
Returns the Unix timestamp value corresponding to the parameters, which are supplied in the order hours, minutes, seconds, month, day, year, and (optionally) whether the value is in Daylight Savings Time. This timestamp is the number of seconds elapsed between the Unix epoch ( January 1, 1970) and the given date and time.
The order of the parameters is different than that of the standard Unix mktime( ) call, to make it simpler to leave out unneeded arguments. Any arguments left out are given the current local date and time.
move_uploaded_file |
bool move_uploaded_file(string from, string to) |
Moves the file from to the new location to. The function moves the file only if from was uploaded by an HTTP POST. If from does not exist or is not an uploaded file, or if any other error occurs, false is returned; if not, if the operation was successful, true is returned.
mt_rand |
int mt_rand([int min, int max]) |
Returns a random number from min to max, inclusive, generated using the Mersenne Twister pseudorandom number generator. If min and max are not provided, returns a random number from 0 to the value returned by mt_getrandmax( ).
mt_srand |
void mt_srand(int seed) |
Seeds the Mersenne Twister generator with seed. You should call this function with a varying number, such as that returned by time( ), before making calls to mt_rand( ).
natcasesort |
void natcasesort(array array) |
Sorts the elements in the given array using a case-insensitive "natural order" algorithm; see natsort for more information.
natsort |
void natsort(array array) |
Sorts the values of the array using "natural order"; numeric values are sorted in the manner expected by language, rather than the often bizarre order in which computers insist on putting them (ASCII ordered). For example:
$array = array("1.jpg", "4.jpg", "12.jpg", "2,.jpg", "20.jpg"); $first = sort($array); // ("1.jpg", "12.jpg", "2.jpg", "20.jpg", "4.jpg") $second = natsort($array); // ("1.jpg", "2.jpg", "4.jpg", "12.jpg", "20.jpg")
next |
mixed next(array array) |
Increments the internal pointer to the element after the current element and returns the value of the element to which the internal pointer is now set. If the internal pointer already points beyond the last element in the array, the function returns false.
Be careful when iterating over an array using this function—if an array contains an empty element or an element with a key value of 0, a value equivalent to false is returned, causing the loop to end. If an array might contain empty elements or an element with a key of 0, use the each function instead of a loop with next.
nl2br |
string nl2br(string string) |
Returns a string created by inserting <br /> before all newline characters in string.
number_format |
string number_format(double number[, int precision[, string decimal_separator, string thousands_separator]]) |
Creates a string representation of number. If precision is given, the number is rounded to that many decimal places; the default is no decimal places, creating an integer. If decimal_separator and thousands_separator are provided, they are used as the decimal-place character and thousands separator, respectively. They default to the English locale versions ("." and ","). For example:
$number = 7123.456; $english = number_format($number, 2); // 7,123.45 $francais = number_format($number, 2, ',', ' '); // 7 123,45 $deutsche = number_format($number, 2, ',', '.'); // 7.123,45
If rounding occurs, proper rounding is performed, which may not be what you expect (see round).
ob_end_clean |
void ob_end_clean( ) |
Turns off output buffering and empties the current buffer without sending it to the client. See Chapter 13 for more information on using the output buffer.
ob_end_flush |
void ob_end_flush( ) |
Sends the current output buffer to the client and stops output buffering. See Chapter 13 for more information on using the output buffer.
ob_get_contents |
string ob_get_contents( ) |
Returns the current contents of the output buffer; if buffering has not been enabled with a previous call to ob_start( ), returns false. See Chapter 13 for more information on using the output buffer.
ob_get_length |
int ob_get_length( ) |
Returns the length of the current output buffer, or false if output buffering isn't enabled. See Chapter 13 for more information on using the output buffer.
ob_gzhandler |
string ob_gzhandler(string buffer[, int mode]) |
This function gzip-compresses output before it is sent to the browser. You don't call this function directly. Rather, it is used as a handler for output buffering using the ob_start( ) function. To enable gzip-compression, call ob_start( ) with this function's name:
<?php ob_start("ob_gzhandler"); ?>
ob_implicit_flush |
void ob_implicit_flush([int flag]) |
If flag is true or unspecified, turns on output buffering with implicit flushing. When implicit flushing is enabled, the output buffer is cleared and sent to the client after any output (such as the printf( ) and echo( ) functions). See Chapter 13 for more information on using the output buffer.
ob_start |
void ob_start([string callback]) |
Turns on output buffering, which causes all output to be accumulated in a buffer instead of being sent directly to the browser. If callback is specified, it is a function (called before sending the output buffer to the client) that can modify the data in any way; the ob_gzhandler( ) function is provided to compress the output buffer in a client-aware manner. See Chapter 13 for more information on using the output buffer.
octdec |
int octdec(string octal) |
Converts octal to its decimal value. Up to a 32-bit number, or 2,147,483,647 decimal (017777777777 octal), can be converted.
opendir |
int opendir(string path) |
Opens the directory path and returns a directory handle for the path that is suitable for use in subsequent readdir( ), rewinddir( ), and closedir( ) calls. If path is not a valid directory, if permissions do not allow the PHP process to read the directory, or if any other error occurs, false is returned.
openlog |
int openlog(string identity, int options, int facility) |
Opens a connection to the system logger. Each message sent to the logger with a subsequent call to syslog( ) is prepended by identity. Various options can be specified by options; OR any options you want to include. The valid options are:
LOG_CONS |
If an error occurs while writing to the system log, write the error to the system console. |
LOG_NDELAY |
Open the system log immediately. |
LOG_ODELAY |
Delay opening the system log until the first message is written to it. |
LOG_PERROR |
Print this message to standard error in addition to writing it to the system log. |
LOG_PID |
Include the PID in each message. |
The third parameter, facility, tells the system log what kind of program is logging to the system log. The following facilities are available:
LOG_AUTH |
Security and authorization errors (deprecated; if LOG_AUTHPRIV is available, use it instead) |
LOG_AUTHPRIV |
Security and authorization errors |
LOG_CRON |
Clock daemon (cron and at) errors |
LOG_DAEMON |
Errors for system daemons not given their own codes |
LOG_KERN |
Kernel errors |
LOG_LPR |
Line printer subsystem errors |
LOG_MAIL |
Mail errors |
LOG_NEWS |
USENET news system errors |
LOG_SYSLOG |
Errors generated internally by syslogd |
LOG_AUTHPRIV |
Security and authorization errors |
LOG_USER |
Generic user-level errors |
LOG_UUCP |
UUCP errors |
pack |
string pack(string format, mixed arg1[, mixed arg2[, ... mixed argN]]) |
Creates a binary string containing packed versions of the given arguments according to format. Each character may be followed by a number of arguments to use in that format, or an asterisk (*), which uses all arguments to the end of the input data. If no repeater argument is specified, a single argument is used for the format character. The following characters are meaningful in the format string:
a |
NUL-byte-padded string |
A |
Space-padded string |
h |
Hexadecimal string, with the low nibble first |
H |
Hexadecimal string, with the high nibble first |
c |
Signed char |
C |
Unsigned char |
s |
16-bit, machine-dependent byte-ordered signed short |
S |
16-bit, machine-dependent byte-ordered unsigned short |
n |
16-bit, big-endian byte-ordered unsigned short |
v |
16-bit, little-endian byte-ordered unsigned short |
i |
Machine-dependent size and byte-ordered signed integer |
I |
Machine-dependent size and byte-ordered unsigned integer |
l |
32-bit, machine-dependent byte-ordered signed long |
L |
32-bit, machine-dependent byte-ordered unsigned long |
N |
32-bit, big-endian byte-ordered unsigned long |
V |
32-bit, little-endian byte-ordered unsigned long |
f |
Float in machine-dependent size and representation |
d |
Double in machine-dependent size and representation |
x |
NUL-byte |
X |
Back up one byte |
@ |
Fill to absolute position (given by the repeater argument) with NUL-bytes |
parse_ini_file |
array parse_ini_file(string filename[, bool process_sections]) |
Loads filename, a file in the standard PHP .ini format, and returns the values in it as an associative array. If process_sections is set and is true, a multidimensional array with values for the sections in the file is returned.
This function does not bring the values in filename into PHP—it is only meant to allow you to create configuration files for your applications in the same format as PHP's php.ini file.
parse_str |
void parse_str(string string[, array variables]) |
Parses string as if coming from an HTTP POST request, setting variables in the local scope to the values found in the string. If variables is given, the array is set with keys and values from the string.
parse_url |
array parse_url(string url) |
Returns an associative array of the component parts of url. The array contains the following values:
fragment |
The named anchor in the URL |
host |
The host |
pass |
The user's password |
path |
The requested path (which may be a directory or a file) |
port |
The port to use for the protocol |
query |
The query information |
scheme |
The protocol in the URL, such as "http" |
user |
The user given in the URL |
The array will not contain values for components not specified in the URL. For example:
$url = "http://www.oreilly.net/search.php#place?name=php&type=book"; $array = parse_url($url); print_r($array); // contains values for "scheme", "host", "path", "query", // and "fragment"
passthru |
void passthru(string command[, int return]) |
Executes command via the shell and outputs the results of the command into the page. If return is specified, it is set to the return status of the command. If you want to capture the results of the command, use exec( ).
pathinfo |
array pathinfo(string path) |
Returns an associative array containing information about path. The following elements are in the returned array:
dirname |
The directory in which path is contained. |
basename |
The basename (see basename) of path, including the file's extension. |
extension |
The extension, if any, on the file's name. Does not include the period at the beginning of the extension. |
pclose |
int pclose(int handle) |
Closes the pipe referenced by handle. Returns the termination code of the process that was run in the pipe.
pfsockopen |
int pfsockopen(string host, int port[, int error[, string message [, double timeout]]]) |
Opens a persistent TCP or UDP connection to a remote host on a specific port. By default, TCP is used; to connect via UDP, host must begin with udp://. If specified, timeout indicates the length of time in seconds to wait before timing out.
If the connection is successful, the function returns a virtual file pointer that can be used with functions such as fgets( ) and fputs( ). If the connection fails, it returns false. If error and message are supplied, they are set to the error number and error string, respectively.
Unlike fsockopen( ), the socket opened by this function does not close automatically after completing a read or write operation on it; you must close it explicitly with a call to fsclose( ).
php_logo_guid |
string php_logo_guid( ) |
Returns an ID that you can use to link to the PHP logo. For example:
<?php $current = basename($PHP_SELF); ?> <img src="<?= "$current?=" . php_logo_guid( ); ?>" border="0" />
php_sapi_name |
string php_sapi_name( ) |
Returns a string describing the server API under which PHP is running; for example, "cgi" or "apache".
php_uname |
string php_uname( ) |
Returns a string describing the operating system under which PHP is running.
phpcredits |
void phpcredits([int what]) |
Outputs information about PHP and its developers; the information that is displayed is based on the value of what. To use more than one option, OR the values together. The possible values of what are:
CREDITS_ALL (default) |
All credits except CREDITS_SAPI. |
CREDITS_GENERAL |
General credits about PHP. |
CREDITS_GROUP |
A list of the core PHP developers. |
CREDITS_DOCS |
Information about the documentation team. |
CREDITS_MODULES |
A list of the extension modules currently loaded and the authors for each. |
CREDITS_SAPI |
A list of the server API modules and the authors for each. |
CREDITS_FULLPAGE |
Indicates that the credits should be returned as a full HTML page, rather than just a fragment of HTML code. Must be used in conjunction with one or more other options; e.g., phpcredits(CREDITS_MODULES | CREDITS_FULLPAGE). |
phpinfo |
void phpinfo([int what]) |
Outputs a whole bunch of information about the state of the current PHP environment, including loaded extensions, compilation options, version, server information, and so on. If speficied, what can limit the output to specific pieces of information; what may contain several options ORed together. The possible values of what are:
INFO_ALL (default) |
All information |
INFO_GENERAL |
General information about PHP |
INFO_CREDITS |
Credits for PHP, including the authors |
INFO_CONFIGURATION |
Configuration and compilation options |
INFO_MODULES |
Currently loaded extensions |
INFO_ENVIRONMENT |
Information about the PHP environment |
INFO_VARIABLES |
A list of the current variables and their values |
INFO_LICENSE |
The PHP license |
popen |
int popen(string command, string mode) |
Opens a pipe to a process executed by running command on the shell.
The parameter mode specifies the permissions to open the file with, which can only be unidirectional (that is, for reading or writing only). mode must be one of the following:
r |
Open file for reading; file pointer will be at beginning of file. |
w |
Open file for writing. If the file exists, it will be truncated to zero length; if the file doesn't already exist, it will be created. |
If any error occurs while attempting to open the pipe, false is returned. If not, the resource handle for the pipe is returned.
pow |
mixed pow(double base, double exponent) |
Returns base raised to the exponent power. When possible, the return value is an integer; if not, it is a double.
prev |
mixed prev(array array) |
Moves the internal pointer to the element before its current location and returns the value of the element to which the internal pointer is now set. If the internal pointer is already set to the first element in the array, returns false. Be careful when iterating over an array using this function—if an array has an empty element or an element with a key value of 0, a value equivalent to false is returned, causing the loop to end. If an array might contain empty elements or an element with a key of 0, use the each( ) function instead of a loop with prev( ).
void print(string string) |
Outputs string. Similar to echo, except that it takes a single argument.
print_r |
bool print_r(mixed value) |
Outputs value in a human-readable manner. If value is a string, integer, or double, the value itself is output; if it is an array, the keys and elements are shown; and if it is an object, the keys and values for the object are displayed. This function returns true.
printf |
int printf(string format[, mixed arg1 ...]) |
Outputs a string created by using format and the given arguments. The arguments are placed into the string in various places denoted by special markers in the format string.
Each marker starts with a percent sign (%) and consists of the following elements, in order. Except for the type specifier, the specifiers are all optional. To include a percent sign in the string, use %%.
A padding specifier denoting the character to use to pad the results to the appropriate string size (given below). Either 0, a space, or any character prefixed with a single quote may be specified; padding with spaces is the default.
An alignment specifier. By default, the string is padded to make it right-justified. To make it left-justified, specify a dash (-) here.
The minimum number of characters this element should contain. If the result would be less than this number of characters, the above specifiers determine the behavior to pad to the appropriate width.
For floating-point numbers, a precision specifier consisting of a period and a number; this dictates how many decimal digits will be displayed. For types other than double, this specifier is ignored.
Finally, a type specifier. This specifier tells printf( ) what type of data is being handed to the function for this marker. There are eight possible types:
b |
The argument is an integer and is displayed as a binary number. |
c |
The argument is an integer and is displayed as the character with that value. |
d |
The argument is an integer and is displayed as a decimal number. |
f |
The argument is a double and is displayed as a floating-point number. |
o |
The argument is an integer and is displayed as an octal (base-8) number. |
s |
The argument is and is displayed as a string. |
x |
The argument is an integer and is displayed as a hexadecimal (base-16) number; lowercase letters are used. |
X |
Same as x, except uppercase letters are used. |
putenv |
void putenv(string setting) |
Sets an environment variable using setting, which is typically in the form name = value.
quoted_printable_decode |
string quoted_printable_decode(string string) |
Decodes string, which is data encoded using the quoted printable encoding, and returns the resulting string.
quotemeta |
string quotemeta(string string) |
Escapes instances of certain characters in string by appending a backslash (\) to them and returns the resulting string. The following characters are escaped: period (.), backslash (\), plus sign (+), asterisk (*), question mark (?), brackets ([ and ]), caret (^), parentheses (( and )), and dollar sign ($).
Copyright © 2003 O'Reilly & Associates. All rights reserved.