Programming PHP
Returns the absolute value of number in the same type (float or integer) as the argument.
Returns the arc cosine of value in radians.
Escapes instances of characters in string by adding a backslash before them. You can specify ranges of characters by separating them by two periods; for example, to escape characters between a and q, use "a..q". Multiple characters and ranges can be specified in characters. The addcslashes( ) function is the inverse of stripcslashes( ).
Escapes characters in string that have special meaning in SQL database queries. Single quotes (''), double quotes (""), backslashes (\), and the NUL-byte ("\0") are escaped. The stripslashes( ) function is the inverse for this function.
Creates an array using the parameters as elements in the array. By using the => operator, you can specify specific indexes for any elements; if no indexes are given, the elements are assigned indexes starting from 0 and incrementing by one. The internal pointer (see current, reset, and next) is set to the first element. $array = array("first", 3 => "second", "third", "fourth" => 4); Note: array is actually a language construct, used to denote literal arrays, but its usage is similar to that of a function, so it's included here.
Returns an array whose elements' keys are the input array's values. The value of each key is the number of times that key appears in the input array as a value.
Returns an array containing all of the values from the first array that are not present in any of the other arrays. The keys of the values are preserved.
Creates an array containing all values from the original array for which the given callback function returns true. If the input array is an associative array, the keys are preserved. For example: function isBig($inValue) { return($inValue > 10); } $array = array(7, 8, 9, 10, 11, 12, 13, 14); $new_array = array_filter($array, "isBig"); // contains (11, 12, 13, 14)
Returns an array in which the elements' keys are the original array's values, and vice versa. If multiple values are found, the last one encountered is retained. If any of the values in the original array are any type except strings and integers, array_flip( ) returns false.
Returns an array whose elements are those from the first array that also exist in every other array.
Returns an array containing all of the keys in the given array. If the second parameter is provided, only keys whose values match value are returned in the array.
Creates an array by applying the callback function referenced in the first parameter to the remaining parameters; the callback function should take as parameters a number of values equal to the number of arrays passed into array_map( ). For example: function multiply($inOne, $inTwo) { return $inOne * $inTwo; } $first = (1, 2, 3, 4); $second = (10, 9, 8, 7); $array = array_map("multiply", $first, $second); // contains (10, 18, 24, 28)
Returns an array created by appending the elements of every array to the previous. If any array has a value with the same string key, the last value encountered for the key is returned in the array; any elements with identical numeric keys are inserted into the resulting array.
Like array_merge( ), creates and returns an array by appending each input array to the previous. Unlike that function, when multiple elements have the same string key, an array containing each value is inserted into the resulting array.
Used to sort several arrays simultaneously, or to sort a multidimensional array in one or more dimensions. The input arrays are treated as columns in a table to be sorted by rows the first array is the primary sort. Any values that compare the same according to that sort are sorted by the next input array, and so on. The first argument is an array; following that, each argument may be an array or one of the following order flags (the order flags are used to change the default order of the sort):
After that, a sorting type from the following list can be specified:
The sorting flags apply only to the immediately preceding array, and they revert to SORT_ASC and SORT_REGULAR before each new array argument. This function returns true if the operation was successful and false if not.
Returns a copy of the input array padded to the length specified by size. Any new elements added to the array have the value of the optional third value. You can add elements to the beginning of the array by specifying a negative size in this case, the new size of the array is the absolute value of the size. If the array already has the specified number of elements or more, no padding takes place and an exact copy of the original array is returned.
Removes the last value from the given array and returns it. If the array is empty (or the argument is not an array), returns NULL.
Adds the given values to the end of the array specified in the first argument and returns the new size of the array. Performs the same function as calling $array[] = $value for each of the values in the list.
Picks a random element from the given array. The second, optional, parameter can be given to specify a number of elements to pick and return. If more than one element is returned, an array of keys is returned, rather than the element's value. Before you call array_rand( ), be sure to seed the random-number generator using srand( ).
Returns a value derived by iteratively calling the given callback function with pairs of values from the array. If the third parameter is supplied, it, along with the first element in the array, is passed to the callback function for the initial call.
Returns an array containing the same elements as the input array, but whose order is reversed. If the second parameter is given and is true, the keys for the elements are preserved; if not, the keys are lost.
Performs a search for a value in an array, as with in_array( ). If the value is found, the key of the matching element is returned; NULL is returned if the value is not found. If strict is specified and is true, a matched element is returned only when it is of the same type and value as value.
Similar to array_pop( ), but instead of removing and returning the last element in the array, it removes and returns the first element in the array. If the array is empty, or if the argument is not an array, returns NULL.
Returns an array containing a set of elements pulled from the given array. If offset is a positive number, elements starting from that index onward are used; if offset is a negative number, elements starting that many elements from the end of the array are used. If the third argument is provided and is a positive number, that many elements are returned; if negative, the sequence stops that many elements from the end of the array. If the third argument is omitted, the sequence returned contains all elements from the offset to the end of the array.
Selects a sequence of elements using the same rules as array_slice( ), but instead of being returned, those elements are either removed or, if the fourth argument is provided, replaced with that array. An array containing the removed (or replaced) elements is returned.
Returns the sum of every element in the array. If all of the values are integers, an integer is returned. If any of the values are doubles, a double is returned.
Creates and returns an array containing each element in the given array. If any values are duplicated, the later values are ignored. Keys from the original array are preserved.
Returns a copy of the given array, with the additional arguments added to the front of the array; the added elements are added as a whole, so the elements as they appear in the array are in the same order as they appear in the argument list. Returns the number of elements in the new array.
Returns an array containing all of the values from the input array. The keys for those values are not retained.
Calls the named function for each element in the array. The function is called with the element's value, key, and optional user data as arguments. To ensure that the function works directly on the values of the array, define the first parameter of the function by reference.
Sorts an array 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.
Returns the arc sine of value in radians.
Sorts an array, 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.
If assertion is true, generates a warning in executing the code. If assertion is a string, assert( ) evaluates that string as PHP code.
If value is specified, sets the assert control option option to value and returns the previous setting. If value is not specified, returns the current value of option. The following values for option are allowed:
Returns the arc tangent of value in radians.
Using the signs of both parameters to determine the quadrant the value is in, returns the arc tangent of x and y in radians.
Decodes data, which is base 64-encoded data, into a string (which may contain binary data). For more information on base-64 encoding, see RFC 2045.
Returns a base 64-encoded version of data. MIME base-64 encoding is designed to allow binary or other 8-bit data to survive transition through protocols that may not be 8-bit safe, such as email messages.
Converts number from one base to another. The base the number is currently in is from, and the base to convert to is to. The bases to convert from and to must be between 2 and 36. Digits in a base higher than 10 are represented with the letters a (10) through z (35). Up to a 32-bit number, or 2,147,483,647 decimal, can be converted.
Returns the filename component from the full path path. If the file's name ends in suffix, that string is removed from the name. For example: $path = "/usr/local/httpd/index.html"; echo(basename($path)); // index.html echo(basename($path, '.html')); // index
Converts binary to a hexadecimal (base-16) value. Up to a 32-bit number, or 2,147,483,647 decimal, can be converted.
Converts binary to a decimal value. Up to a 32-bit number, or 2,147,483,647 decimal, can be converted.
Calls the function given in the first parameter. Additional parameters are used as parameters when calling the function. The comparison to check for a matching function is case-insensitive. Returns the value returned by the function.
Similar to call_user_func( ), this function calls the function named function with the parameters in the array parameters. The comparison to check for a matching function is case-insensitive. Returns the value returned by the function.
Calls the method given in the first parameter on the object in the second parameter. Additional parameters are used as parameters when calling the method. The comparison to check for a matching method name is case-insensitive. Returns the value returned by the function.
Similar to call_user_method( ), this function calls the method named by the first parameter on the object in the second parameter. If given, the third parameter is an array of values used as parameters for the call to the object method. The comparison to check for a matching method name is case-insensitive. Returns the value returned by the function.
Returns the smallest integer value greater than or equal to number.
Sets the current working directory to path; returns true if the operation was successful and false if not.
Returns true if the month, date, and year as given in the parameters are valid, and false if not. A date is considered valid if the year falls between 1 and 32767 inclusive, the month is between 1 and 12 inclusive, and the day is within the number of days the specified month has.
Searches DNS records for a host having the given type. Returns true if any records are found, and false if none are found. The host type can take any of the following values (if no value is specified, MX is the default):
Changes the group for the file path to group; PHP must have appropriate privileges for this function to work. Returns true if the change was successful and false if not.
Attempts to change the permissions of path to mode. 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.
This is an alias for ltrim( ).
Changes ownership for the file path to the user named user. PHP must have appropriate privileges (generally, root for this function) for the function to operate. Returns true if the change was successful and false if not.
Returns a string consisting of the single ASCII character char.
Changes the root directory of the current process to path. You cannot use chroot( ) to restore the root directory to / when running PHP in a web server environment. Returns true if the change was successful and false if not.
Inserts postfix into string every size characters and at the end of the string; returns the resulting string. If not specified, postfix defaults to \r\n and size defaults to 76. This function is most useful for encoding data to the RPF 2045 standard. For example: $data = "...some long data..."; $converted = chunk_split(base64_encode($data));
Returns true if a class with the same name as the string has been defined; if not, it returns false. The comparison for class names is case-insensitive.
Clears the file status functions cache. The next call to any of the file status functions will retrieve the information from the disk.
Closes the directory stream referenced by handle. See opendir for more information on directory streams. If handle is not specified, the most recently opened directory stream is closed.
Closes the file descriptor used to write to the system logger after an openlog( ) call; returns true.
Creates an array by retrieving the values of the variables named in the parameters. If any of the parameters are arrays, the values of variables named in the arrays are also retrieved. The array returned is an associative array, with the keys being the arguments provided to the function and the values being the values of the named variables. This function is the opposite of extract( ).
Converts value from one Cyrillic set to another. The from and to parameters are single-character strings representing the set and have the following valid values:
Copies the file at path to destination. If the operation succeeds, the function returns true; otherwise, it returns false.
Returns the cosine of value in radians.
Returns the number of elements in the value; for arrays, this is the number of elements in the array; for any other value, this is 1. If the parameter is a variable and the variable is not set, 0 is returned.
Returns the number of occurrences of each byte value from 0-255 in string; mode determines the form of the result. The possible values of mode are:
Calculates and returns the cyclic redundancy checksum (CRC) for value.
Creates an anonymous function with the given arguments and code; returns a generated name for the function. Such anonymous functions (also called lambda functions) are useful for short-term callback functions, such as when using usort( ).
Encrypts string using the DES encryption algorithm seeded with the two-character salt value salt. If salt is not supplied, a random salt value is generated the first time crypt( ) is called in a script; this value is used on subsequent calls to crypt( ). Returns the encrypted string.
Returns the value of the element to which the internal pointer is set. The first time current( ) is called, or when current( ) is called after reset, the pointer is set to the first element in the array.
Formats a time and date according to the format string provided in the first parameter. If the second parameter is not specified, the current time and date is used. The following characters are recognized in the format string:
Any characters in the format string not matching one of the above will be kept in the resulting string as-is.
Converts decimal to a binary representation of it. Up to a 32-bit number, or 2,147,483,647 decimal, can be converted.
Converts decimal to a hexadecimal (base-16) representation of it. Up to a 32-bit number, or 2,147,483,647 decimal (0x7FFFFFFF hexadecimal), can be converted.
Converts decimal to an octal (base-8) representation of it. Up to a 32-bit number, or 2,147,483,647 decimal (017777777777 octal), can be converted.
Initializes all variables and constants used by the syslog functions openlog( ), syslog( ), and closelog( ). This function should be called before using any of the syslog functions.
Converts number from degrees to radians and returns the result.
Returns the directory component of path. This includes everything up to the filename portion (see basename) and doesn't include the trailing path separator.
Returns the number of bytes of free space available on the disk partition or filesystem at path.
Returns the number of bytes of total space available (including both used and free) on the disk partition or filesystem at path.
Dynamically loads the PHP extension given in filename.
Returns the floating-point value for value. If value is a nonscalar value (object or array), the function returns 0.
Creates an array containing the keys and values of the element currently pointed at by the array's internal pointer. The array contains four elements: elements with the keys 0 and key from the element contain the key of the element, and elements with the keys 1 and value contain the value of the element. If the internal pointer of the array points beyond the end of the array, each( ) returns false.
Outputs the given strings. echo is a language construct, and enclosing the parameters in parentheses is optional, unless multiple parameters are given in this case, you cannot use parentheses.
Returns true if value is either 0 or not set, and false otherwise.
Advances the array's internal pointer to the last element and returns the element's value.
Searches string for the regular expression pattern. If given, the array matches is filled with the subpattern matches. Returns true if the pattern matched in string and false if not. See Chapter 4 for more information on using regular expressions.
Searches for all occurrences of the regular expression pattern in string, replaces them with replace, and returns the result.
Searches string for the regular expression pattern (the pattern matching is case-insensitive). If given, the array matches is filled with the subpattern matches. Returns true if the pattern matched in string and false if not. See Chapter 4 for more information on using regular expressions. This is a case-insensitive version of ereg( ).
Searches for all occurrences of the regular expression pattern in string, replaces them with replace, and returns the result. The pattern matching is case-insensitive. This is a case-insensitive version of ereg_replace( ).
Records an error message to the web server's error log, to an email address, or to a file. The first parameter is the message to log. The type is one of the following:
Sets the level of errors reported by PHP to level and returns the current level; if level is omitted, the current level of error reporting is returned. The following values are available for the function:
Any number of these options can be ORed together, so that errors in each of the levels are reported. For example, the following code turns off user errors and warnings, performs some actions, then restores the original level: <?php $level = error_reporting(); error_reporting($level & ~(E_USER_ERROR | E_USER_WARNING)); // do some stuff error_reporting($level); ?>
Properly escapes argument so it can be used as a safe argument to a shell function. When directly passing user input (such as from forms) to a shell command, you should use this function to escape the data to ensure that the argument isn't a security risk.
Escapes any characters in command that could cause a shell command to run additional commands. When directly passing user input (such as from forms) to the exec( ) or system( ) functions, you should use this function to escape the data to ensure that the argument isn't a security risk.
Executes command via the shell and returns the last line of output from the command's result. If output is specified, it is filled with the lines returned by the command. If return is specified, it is set to the return status of the command. If you want to have the results of the command output into the PHP page, use passthru( ).
Returns e raised to the number power.
Returns an array of substrings created by splitting string wherever separator is found. If supplied, a maximum of limit substrings will be returned, with the last substring returned containing the remainder of the string. If separator is not found, returns the original string.
Returns true if the named extension is loaded or false if it is not.
Sets the value of variables to the values of elements from an array. For each element in the array, the key is used to determine the variable name to set, and that variable is set to the value of the element. The second argument, if given, takes one of the following values to determine behavior if the values in the array have the same name as variables already existing in the local scope:
The function returns the number of successfully set variables. |