Programming PHP
This function is an alias of implode( ).
Returns the key for the element currently pointed to by the internal array pointer.
Returns true if array contains a key with the value key. If no such key is available, returns false.
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.
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.
Returns a pseudorandom number between 0 and 1, inclusive, using a linear congruential- number generator.
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.
Creates a hard link to path at the path new. Returns true if the link was successfully created and false if not.
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.
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.
Returns an associative array of information about the current locale's numeric and monetary formatting. The array contains the following elements:
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:
If a numeric array is returned, the values are in the order given above.
Returns the natural log of number.
Returns the base-10 logarithm of number.
Converts an IPv4 address to a dotted (standard format) address.
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.
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.
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.
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.
Calculates the MD5 hash of string and returns it.
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.
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.
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.
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.
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.
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.
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.
Returns the largest value that can be returned by mt_rand( ).
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( ).
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( ).
Sorts the elements in the given array using a case-insensitive "natural order" algorithm; see natsort for more information.
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")
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.
Returns a string created by inserting <br /> before all newline characters in string.
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).
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.
Sends the current output buffer to the client and stops output buffering. See Chapter 13 for more information on using the output buffer.
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.
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.
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"); ?>
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.
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.
Converts octal to its decimal value. Up to a 32-bit number, or 2,147,483,647 decimal (017777777777 octal), can be converted.
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.
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:
The third parameter, facility, tells the system log what kind of program is logging to the system log. The following facilities are available:
Returns the ASCII value of the first character in string.
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:
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.
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.
Returns an associative array of the component parts of url. The array contains the following values:
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"
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( ).
Returns an associative array containing information about path. The following elements are in the returned array:
Closes the pipe referenced by handle. Returns the termination code of the process that was run in the pipe.
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( ).
Returns an ID that you can use to link to the PHP logo. For example: <?php $current = basename($PHP_SELF); ?> <img src="/books/2/636/1/html/2/<?= "$current?=" . php_logo_guid( ); ?>" border="0" />
Returns a string describing the server API under which PHP is running; for example, "cgi" or "apache".
Returns a string describing the operating system under which PHP is running.
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:
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:
Returns the version of the currently running PHP parser.
Returns an approximate value of pi.
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:
If any error occurs while attempting to open the pipe, false is returned. If not, the resource handle for the pipe is returned.
This function is an alias for current( ).
Returns base raised to the exponent power. When possible, the return value is an integer; if not, it is a double.
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( ).
Outputs string. Similar to echo, except that it takes a single argument.
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.
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 %%.
Sets an environment variable using setting, which is typically in the form name = value.
Decodes string, which is data encoded using the quoted printable encoding, and returns the resulting 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 ($). |