AppendixB.PHP Function Reference


Appendix B. PHP Function Reference

This appendix details the most commonly used PHP functionsthe array, file, and string functions.

Table B-1. The PHP Array Functions

Function

Does This

array array_change_key_case (array input [, int case])

Changes case of an array's string keys

array array_chunk(array input, int size [, bool preserve_keys])

Divides an array into chunks

array array_combine(array keys, array values)

Makes an array

array array_count_values (array input)

Counts the values of an array

array array_diff_assoc(array array1,array array2 [, array ...])

Returns the difference of two associative arrays

array array_diff_assoc(array array1, array array2 [, array ..., callback key_compare_func])

Returns the difference of arrays with additional index check, performed by a callback function

array array_diff(array array1, array array2 [, array ...])

Returns the difference of two arrays

array array_fill(int start_index, int num, mixed value)

Fills an array with values

array array_filter(array input callback callback])

Filters elements of an array using a callback function

array array_flip(array trans)

Exchanges keys with their values in an array

array array_intersect_assoc(array array1, array array2 [, array ...])

Returns the intersection of arrays with additional index check

array array_intersect(array array1, array array2 [, array ...])

Returns the simple intersection of arrays

bool array_key_exists(mixed key, array search)

Checks if the specified key or index exists in the array

array array_keys(array input [, mixed search_value])

Return the keys of an array

array array_map(mixed callback, array arr1 [, array ...])

Applies the callback function to the elements of the arrays

array array_merge_recursive(array array1, array array2 [, array ...])

Merges two or more arrays recursively

array array_merge(array array1, array array2 [, array ...])

Merges two or more arrays simply

bool array_multisort(array ar1 [, mixed arg [, mixed ... [, array ...]]])

Sorts multi-dimensional arrays

array array_pad(array input, int pad_size, mixed pad_value)

Pads array to the given length with a value

mixed array_pop(array array)

Pops an element from the end of an array

int array_push(array array, mixed var [, mixed ...])

Pushes elements onto the end of array

mixed array_rand(array input [, int num_req])

Picks random entries out of an array

mixed array_reduce(array input, callback function [, int initial])

Iteratively reduces the array to a single value using a callback function

array array_reverse(array array [, bool preserve_keys])

Returns array with elements in reverse order

mixed array_search(mixed needle, array haystack [, bool strict])

Searches the array for a specified value; returns the key if successful

mixed array_shift(array array)

Shifts an element off the beginning of array

array array_slice(array array, int offset [, int length])

Extracts a slice of an array

array array_splice(array input, int offset [, int length [, array replacement]])

Removes a part of the array and replaces it

mixed array_sum(array array)

Returns the sum of values in an array

array array_udiff_assoc(array array1, array array2 [, array ...,callback data_compare_func])

Returns the difference of arrays with additional index check; uses a callback function

array array_udiff_uassoc(array array1, array array2 [, array ..., callback data_compare_func, callback key_compare_func])

Returns the difference of arrays with additional index check

array array_udiff(array array1, array array2 [, array ..., callback data_compare_func])

Returns the difference of arrays, using a callback function for comparison

array array_unique(array array)

Removes duplicate values from an array

int array_unshift(array array, mixed var [, mixed ...])

Prepends elements to the beginning of an array

array array_values(array input)

Returns the values of an array

bool array_walk(array array, callback function [, mixed userdata])

Calls a function on every member of an array

array array([mixed ...])

Makes an array

bool arsort(array array [, int sort_flags])

Sorts an array in reverse order while maintaining index association

bool asort(array array [, int sort_flags])

Sorts an array while maintaining index association

array compact(mixed varname [, mixed ...])

Compacts an array

int count(mixed var [, int mode])

Counts elements in a variable

mixed current(array array)

Returns the current element in an array

array each(array array)

Returns the current key and value pair from an array

mixed end(array array)

Move the internal pointer of an array to the last element

int extract(array var_array [, int extract_type [, string prefix]])

Imports variables into the symbol table from an array

bool in_array(mixed needle, array haystack [, bool strict])

Checks if a value exists in an array

mixed key(array array)

Gets a key from an associative array

bool krsort(array array [, int sort_flags])

Sorts an array by key in reverse order

bool ksort(array array [, int sort_flags])

Sorts an array by key

void list(mixed ...)

Assigns variables as if they were an array

void natcasesort(array array)

Sorts an array using a case-insensitive "natural sort"

void natsort(array array)

Sorts an array using a "natural sort" algorithm

mixed next(array array)

Advances the internal array pointer of an array

mixed pos(array array)

Same as current()

mixed prev(array array)

Moves the internal array pointer back one element

array range(int low, int high [, int step])

Makes an array containing a range of elements

mixed reset(array array)

Sets the internal pointer of an array to the first element

bool rsort(array array [, int sort_flags])

Sorts an array in reverse order

void shuffle(array array)

Shuffles an array

int sizeof(mixed var [, int mode])

Same as count()

bool sort(array array [, int sort_flags])

Sorts an array

bool uasort(array array, callback cmp_function)

Sorts an array with a user-defined comparison function while maintaining index association

bool uksort(array array, callback cmp_function)

Sorts an array by keys using a comparison function

bool usort(array array, callback cmp_function)

Sorts an array by values using a comparison function


Table B-2. The PHP File Functions

Function

Does This

string basename(string path [, string suffix])

Returns the filename part of a path

bool chgrp(string filename, mixed group)

Changes a file's group

bool chown(string filename, mixed user)

Changes a file's owner

void clearstatcache(void)

Clears a file's file status cache

bool copy(string source, string dest)

Copies a file

void delete(string file)

Deletes a file

string dirname(string path)

Returns the directory name part of a path

float disk_free_space(string directory)

Returns available space in directory

float disk_total_space(string directory)

Returns the total size of a directory

float diskfreespace(string directory)

Same as disk_free_space()

bool fclose(resource handle)

Closes an open file

bool feof(resource handle)

Tests for end-of-file on a file

bool fflush(resource handle)

Flushes the output to a file

string fgetc(resource handle)

Gets a character from file

array fgetcsv(resource handle, int length [, string delimiter [, string enclosure]])

Gets a line from file and parses for CSV fields

string fgets(resource handle [, int length])

Gets a line from a file

string fgetss(resource handle, int length [, string allowable_tags])

Gets a line from file and strips HTML tags

bool file_exists(string filename)

Checks whether a file or directory exists

string file_get_contents(string filename [, bool use_include_path [, resource context]])

Reads entire file into a string

int file_put_contents(string filename, string data [, int flags [, resource context]])

Writes a string to a file

array file(string filename [, int use_include_path [, resource context]])

Reads an entire file into an array

int fileatime(string filename)

Gets the last access time of a file

int filectime(string filename)

Gets the change time of a file

int filegroup(string filename)

Gets a file group

int fileinode(string filename)

Gets a file inode

int filemtime(string filename)

Gets a file's modification time

int fileowner(string filename)

Gets a file's owner

int fileperms(string filename)

Gets a file's permissions

int filesize(string filename)

Gets a file size

string filetype(string filename)

Gets a file type

bool flock(resource handle, int operation [, int &wouldblock])

Sets advisory file locking

array fnmatch(string pattern, string string [, int flags])

Matches a filename against a pattern

resource fopen(string filename, string mode [, int use_include_path [, resource zcontext]])

Opens a file or URL

int fpassthru(resource handle)

Outputs all remaining data on a file

int fputs(resource handle, string string [, int length])

Same as fwrite()

string fread(resource handle, int length)

Binary-safe file read

mixed fscanf(resource handle, string format [, string var1])

Parses input from a file according to a format

int fseek(resource handle, int offset [, int whence])

Seeks in a file

array fstat(resource handle)

Gets information about a file

int ftell(resource handle)

Returns the file read/write position

bool ftruncate(resource handle, int size)

Truncates a file to a specified length

int fwrite(resource handle, string string [, int length])

Binary-safe file write

array glob(string pattern [, int flags])

Return pathnames matching a pattern

bool is_dir(string filename)

Returns whether the filename is a directory

bool is_executable(string filename)

Returns whether the filename is executable

bool is_file(string filename)

Returns whether the filename is a regular file

bool is_link(string filename)

Returns whether the filename is a symbolic link

bool is_readable(string filename)

Returns whether the filename is readable

bool is_uploaded_file(string filename)

Returns whether the file was uploaded using HTTP POST

bool is_writable(string filename)

Returns whether the filename is writable

bool is_writeable(string filename)

Same as is_writable()

bool link(string target, string link)

Makes a hard link

int linkinfo(string path)

Returns information about a link

array lstat(string filename)

Returns information about a file or symbolic link

bool mkdir(string pathname [, int mode [, bool recursive [, resource context]]])

Makes a directory

bool move_uploaded_file(string filename, string destination)

Moves an uploaded file to a new location

array parse_ini_file(string filename [, bool process_sections])

Parses a configuration file

array pathinfo(string path)

Returns information about a file path

int pclose(resource handle)

Closes a process file

resource popen(string command, string mode)

Opens a process file

int readfile(string filename [, bool use_include_path [, resource context]])

Outputs a file

string readlink(string path)

Returns the target of a symbolic link

string realpath(string path)

Returns an absolute pathname

bool rename(string oldname, string newname [, resource context])

Renames a file or directory

bool rewind(resource handle)

Rewinds the position of a file

bool rmdir(string dirname [, resource context])

Deletes a directory

int set_file_buffer(resource stream, int buffer)

Same as stream_set_write_buffer()

array stat(string filename)

Returns information about a file

bool symlink(string target, string link)

Makes a symbolic link

string tempnam(string dir, string prefix)

Makes a file with a unique file name

resource tmpfile(void)

Makes a temporary file

bool touch(string filename [, int time [, int atime]])

Sets access and modification time of file

int umask([int mask])

Changes the current umask

bool unlink(string filename [, resource context])

Deletes a file


Table B-3. The PHP String Functions

Function

Does This

string addcslashes(string str, string charlist)

Quotes a string with slashes using the C style

string addslashes(string str)

Quotes a string using slashes

string bin2hex(string str)

Converts binary data into hexadecimal

string chop(string str [, string charlist])

Same as rtrim()

string chr(int ascii)

Returns a specific character

string chunk_split(string body [, int chunklen [, string end]])

Divides a string into smaller chunks

string convert_cyr_string(string str, string from,string to)

Converts from one Cyrillic character set to another

mixed count_chars(string string [, int mode])

Returns information about characters used in a string

int crc32(string str)

Returns the crc32 polynomial of a string

string crypt(string str [, string salt])

Creates one-way string encryption

void echo(string arg1 [, string argn...])

Outputs one or more strings

array explode(string separator, string string [, int limit])

Divides a string using a string

int fprintf(resource handle, string format [, mixed args])

Writes a formatted string to a stream

array get_html_translation_table(int table [, int quote_style])

Returns the translation table that is used by htmlspecialchars() and htmlentities()

string hebrev(string hebrew_text [, int max_chars_per_line])

Converts logical Hebrew text to visual text

string hebrevc(string hebrew_text [, int max_chars_per_line])

Converts logical Hebrew text to visual text including newline conversion

string html_entity_decode(string string [, int quote_style [, string charset]])

Converts all HTML entities to theirapplicable characters

string htmlentities(string string [, int quote_style [, string charset]])

Converts all applicable characters to HTML entities

string htmlspecialchars(string string [, int quote_style [, string charset]])

Converts special characters to HTML entities

string implode(string glue, array pieces)

Joins array elements using a string

string join(string glue, array pieces)

Same as implode()

int levenshtein(string str1, string str2)

Returns the Levenshtein distance between two strings

array localeconv(void)

Gets numeric formatting data

string ltrim(string str [, string charlist])

Strips whitespace from the beginning of a string

string md5_file(string filename [, bool raw_output])

Returns the md5 hash of a specified filename

string md5(string str [, bool raw_output])

Returns the md5 hash of a string

string metaphone(string str)

Returns the metaphone key of a string

string money_format(string format, float number)

Formats a number as a currency string

string nl_langinfo(int item)

Queries language and locale information

string nl2br(string string)

Inserts HTML line breaks before all newlines in a string

string number_format(float number [, int decimals])

Formats a number with grouped thousands

int ord(string string)

Returns ASCII value of character

void parse_str(string str [, array arr])

Parses the string into variables

int print(string arg)

Outputs a string

void printf(string format [, mixed args])

Outputs a formatted string

string quoted_printable_decode(string str)

Converts a quoted-printable string to an 8-bit string

string quotemeta(string str)

Quotes meta characters

string rtrim(string str [, string charlist])

Strips whitespace from the end of a string

string setlocale(mixed category, string locale [, string ...])

Sets locale information

string sha1_file(string filename [, bool raw_output])

Returns the sha1 hash of a file

string sha1(string str [, bool raw_output])

Returns the sha1 hash of a string

int similar_text(string first, string second [, float percent])

Returns the similarity between two strings

string soundex(string str)

Returns the soundex key of a string

string sprintf(string format [, mixed args])

Returns a formatted string

mixed sscanf(string str, string format [, string var1])

Parses input from a string according to a format

mixed str_ireplace(mixed search, mixed replace, mixed subject [, int &count])

Case-insensitive version of str_replace()

string str_pad(string input, int pad_length [, string pad_string [, int pad_type]])

Pads a string to a certain length with another string

string str_repeat(string input, int multiplier)

Repeats a string

mixed str_replace(mixed search, mixed replace, mixed subject [, int &count])

Replaces all occurrences of the search string with the replacement string

string str_rot13(string str)

Performs the rot13 transform on a string

string str_shuffle(string str)

Randomly shuffles a string

array str_split(string string [, int split_length])

Converts a string to an array

mixed str_word_count(string string [, int format])

Returns information about words used in a string

int strcasecmp(string str1, string str2)

Binary safe case-insensitive string comparison

string strchr(string haystack, string needle)

Same as strstr()

int strcmp(string str1, string str2)

Compares strings in a binary-safe way

int strcoll(string str1, string str2)

Compares strings in a locale-based way

int strcspn(string str1, string str2)

Returns length of initial segment not matching mask

string strip_tags(string str [, string allowable_tags])

Strips HTML and PHP tags

string stripcslashes(string str)

Un-quotes string quoted with addcslashes()

int stripos(string haystack, string needle [, int offset])

Returns position of first occurrence of a case-insensitive string

string stripslashes(string str)

Un-quotes string quoted with addslashes()

string stristr(string haystack, string needle)

Case-insensitive strstr()

int strlen(string str)

Gets string length

int strnatcasecmp(string str1, string str2)

Case insensitive string comparisons using a "natural sort" algorithm

int strnatcmp(string str1, string str2)

String comparisons using a "natural sort" algorithm

int strncasecmp(string str1, string str2, int len)

Binary-safe case-insensitive string comparison of a given number of characters

int strncmp(string str1, string str2, int len)

Binary-safe string comparison of a given number of characters

int strpos(string haystack, string needle [, int offset])

Returns the position of first occurrence of a string

string strrchr(string haystack, char needle)

Returns the last occurrence of a character in a string

string strrev(string string)

Reverses a string

int strripos(string haystack, string needle [, int offset])

Returns position of last occurrence ofa case-insensitive string in a string

int strrpos(string haystack, string needle [, int offset])

Returns position of last occurrence ofa char in a string

int strspn(string str1, string str2)

Returns length of initial segment matching mask

string strstr(string haystack, string needle)

Returns first occurrence of a string

string strtok(string arg1, string arg2)

Tokenizes a string

string strtolower(string str)

Makes a string lowercase

string strtoupper(string string)

Makes a string uppercase

string strtr(string str, string from, string to)

Translates characters

int substr_compare(string main_str, string str, int offset [, int length [, bool case_sensitivity]])

Binary-safe comparison of two strings from an offset, up to length characters

int substr_count(string haystack, string needle)

Counts the number of substring occurrences

string substr_replace(string string, string replacement, int start [, int length])

Replaces text in a part of a string

string substr(string string, int start [, int length])

Returns part of a string

string trim(string str [, string charlist])

Strips whitespace from both the beginning and end of a string

string ucfirst(string str)

Uppercases a string's first character

string ucwords(string str)

Uppercases the first character of each word in a string

void vprintf(string format, array args)

Outputs a formatted string

string vsprintf(string format, array args)

Creates and returns a formatted string

string wordwrap(string str [, int width [, string break [, boolean cut]]])

Wraps a string to a specified number of characters




    Spring Into PHP 5
    Spring Into PHP 5
    ISBN: 0131498622
    EAN: 2147483647
    Year: 2006
    Pages: 254

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net