Programming PHP
Closes the file referenced by handle; returns true if successful and false if not.
Returns true if the marker for the file referenced by handle is at the end of the file (EOF) or if an error occurs. If the marker is not at EOF, returns false.
Commits any changes to the file referenced by handle to disk, ensuring that the file contents are on disk and not just in a disk buffer. If the operation succeeds, the function returns true; otherwise it returns false.
Returns the character at the marker for the file referenced by handle and moves the marker to the next character. If the marker is at the end of the file, the function returns false.
Reads the next line from the file referenced by handle and parses the line as a comma-separated values (CSV) line. The longest line to read is given by length. If supplied, delimiter is used to delimit the values for the line instead of commas. For example, to read and display all lines from a file containing tab-separated values, use: $fp = fopen("somefile.tab", "r"); while($line = fgetcsv($fp, 1024, "\t")) { print "<p>" . count($line) . "fields:</p>"; print_r($line); } fclose($fp);
Reads a string from the file referenced by handle; a string of no more than length characters is returned, but the read ends at length - 1 (for the end-of-line character) characters, at an end-of-line character, or at EOF. Returns false if any error occurs.
Reads a string from the file referenced by handle; a string of no more than length characters is returned, but the read ends at length-1 (for the end-of-line character) characters, at an end-of-line character, or at EOF. Any PHP and HTML tags in the string, except those listed in tags, are stripped before returning it. Returns false if any error occurs.
Reads the file at path and returns an array of lines from the file. The strings include the end-of-line characters. If include is specified and is true, the include path is searched for the file.
Returns true if the file at path exists and false if not.
Returns the last access time, as a Unix timestamp value, for the file path. Because of the cost involved in retrieving this information from the filesystem, this information is cached; you can clear the cache with clearstatcache( ).
Returns the creation date, as a Unix timestamp value, for the file path. Because of the cost involved in retrieving this information from the filesystem, this information is cached; you can clear the cache with clearstatcache( ).
Returns the group ID of the group owning the file path. Because of the cost involved in retrieving this information from the filesystem, this information is cached; you can clear the cache with clearstatcache( ).
Returns the inode number of the file path, or false if an error occurs. This information is cached; see clearstatcache.
Returns the last-modified time, as a Unix timestamp value, for the file path. This information is cached; you can clear the cache with clearstatcache( ).
Returns the user ID of the owner of the file path, or false if an error occurs. This information is cached; you can clear the cache with clearstatcache( ).
Returns the file permissions for the file path; returns false if any error occurs. This information is cached; you can clear the cache with clearstatcache( ).
Returns the size, in bytes, of the file path. If the file does not exist, or any other error occurs, the function returns false. This information is cached; you can clear the cache with clearstatcache( ).
Returns the type of file given in path. The possible types are:
Attempts to lock the file path of the file specified by handle. The operation is one of the following values:
If specified, would_block is set to true if the operation would cause a block on the file. The function returns false if the lock could not be obtained, and true if the operation succeeded. Because file locking is implemented at the process level on most systems, flock( ) cannot prevent two PHP scripts running in the same web server process from accessing a file at the same time.
Returns the largest integer value less than or equal to number.
Sends the current output buffer to the client and empties the output buffer. See Chapter 13 for more information on using the output buffer.
Opens the file specified by path and returns a file resource handle to the open file. If path begins with http://, an HTTP connection is opened and a file pointer to the start of the response is returned. If path begins with ftp://, an FTP connection is opened and a file pointer to the start of the file is returned; the remote server must support passive FTP. If path is php://stdin, php://stdout, or php://stderr, a file pointer to the appropriate stream is returned. The parameter mode specifies the permissions to open the file with. It must be one of the following:
If include is specified and is true, fopen( ) tries to locate the file in the current include path. If any error occurs while attempting to open the file, false is returned.
Outputs the file pointed to by handle and closes the file. The file is output from the current file pointer location to EOF. If any error occurs, false is returned; if the operation is successful, true is returned.
This function is an alias for fwrite( ).
Reads length bytes from the file referenced by handle and returns them as a string. If fewer than length bytes are available before EOF is reached, the bytes up to EOF are returned.
Reads data from the file referenced by handle and returns a value from it based on format. For more information on how to use this function, see sscanf. If the optional name1 through nameN parameters are not given, the values scanned from the file are returned as an array; otherwise, they are put into the variables named by name1 through nameN.
Moves the file pointer in handle to the byte offset. If from is specified, it determines how to move the file pointer. from must be one of the following values:
This function returns 0 if the function was successful and -1 if the operation failed.
Opens a 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 the protocol udp://. If specified, timeout indicates the length of time in seconds to wait before timing out. If the connection is successful, a virtual file pointer is returned, which can be used with functions such as fgets( ) and fputs( ). If the connection fails, false is returned. If error and message are supplied, they are set to the error number and error string, respectively.
Returns an associative array of information about the file referenced by handle. The following values(given here with their numeric and key indexes) are included in the array:
Returns the byte offset to which the file referenced by handle is set. If an error occurs, returns false.
Truncates the file referenced by handle to length bytes. Returns true if the operation is successful and false if not.
Returns the index element in the function argument array. If called outside a function, or if index is greater than the number of arguments in the argument array, func_get_arg( ) generates a warning and returns false.
Returns the array of arguments given to the function as an indexed array. If called outside a function, func_get_args( ) returns false and generates a warning.
Returns the number of arguments passed to the current user-defined function. If called outside a function, func_num_args( ) returns false and generates a warning.
Returns true if a function with function has been defined, and false otherwise. The comparison to check for a matching function is case-insensitive.
Writes string to the file referenced by handle. The file must be open with write privileges. If length is given, only that many bytes of the string will be written. Returns the number of bytes written, or -1 on error.
Returns an object containing information about the user's current browser, as found in $HTTP_USER_AGENT, or the browser identified by the user agent name. The information is gleaned from the browscap.ini file. The version of the browser and various capabilities of the browser, such as whether or not the browser supports frames, cookies, and so on, are returned in the object.
Returns the value of the PHP configuration variable name. If name does not exist, get_cfg_var( ) returns false. Only those configuration variables set in a configuration file, as returned by cfg_file_path( ), are returned by this function compile-time settings and Apache configuration file variables are not returned.
Returns the name of the class of which the given object is an instance. The class name is returned as a lowercase string.
If the parameter is a string, returns an array containing the names of each method defined for the specified class. If the parameter is an object, this function returns the methods defined in the class of which the object is an instance.
Returns an associative array of default properties for the given class. For each property, an element with a key of the property name and a value of the default value is added to the array. Properties that do not have default values are not returned in the array.
Returns the name of the user under whose privileges the current PHP script is executing.
Returns an array containing the name of each defined class. This includes any classes defined in extensions currently loaded in PHP.
Returns an associative array of all constants defined by extensions and the define( ) function and their values.
Returns an array containing the name of each defined function. The returned array is an associative array with two keys, internal and user. The value of the first key is an array containing the names of all internal PHP functions; the value of the second key is an array containing the names of all user-defined functions.
Returns an array of all defined environment, server, and user-defined variables.
Returns an array of functions provided by the extension specified by name.
Returns the translation table used by either htmlspecialchars( ) or htmlentities( ). If which is HTML_ENTITIES, the table used by htmlentities( ) is returned; if which is HTML_SPECIALCHARS, the table used by htmlspecialchars( ) is returned. Optionally, you can specify which quotes style you want returned; the possible values are the same as those in the translation functions:
Returns an array of the files included into the current script by include( ), include_once( ), require( ), and require_once( ).
Returns an array containing the names of every extension compiled and loaded into PHP.
Returns the current value of the quotes state for GET/POST/cookie operations. If true, all single quotes (''), double quotes (""), backslashes (\), and NUL-bytes ("\0") are automatically escaped and unescaped as they go from the server to the client and back.
Parses the file path and extracts any HTML meta tags it locates. Returns an associative array, the keys of which are name attributes for the meta tags, and the values of which are the appropriate values for the tags. The keys are in lowercase, regardless of the case of the original attributes. If include is specified and true, the function searches for path in the include path.
Returns an associative array of the properties for the given object. For each property, an element with a key of the property name and a value of the current value is added to the array. Properties that do not have current values are not returned in the array, even if they are defined in the class.
Returns the name of the parent class for the given object. If the object does not inherit from another class, returns an empty string.
This function is an alias for get_included_files( ).
Returns a string representing the type of the specified resource handle. If handle is not a valid resource, the function generates an error and returns false. The kinds of resources available are dependent on the extensions loaded, but include "file", "mysql link", and so on.
Returns the path of the PHP process's current working directory.
Returns an associative array containing values for various components for the given timestamp time and date. If no timestamp is given, the current date and time is used. The array contains the following keys and values:
Returns the value of the environment variable name. If name does not exist, getenv( ) returns false.
Returns the hostname of the machine with the IP address address. If no such address can be found, or if address doesn't resolve to a hostname, address is returned.
Returns the IP address for host. If no such host exists, host is returned.
Returns an array of IP addresses for host. If no such host exists, returns false.
Returns the Unix timestamp value for the last-modification date of the file containing the current script. If an error occurs while retrieving the information, returns false.
Searches DNS for all Mail Exchanger (MX) records for host. The results are put into the array hosts. If given, the weights for each MX record are put into weights. Returns true if any records are found and false if none are found.
Returns the inode value of the file containing the current script. If an error occurs, returns false.
Returns the process ID for the PHP process executing the current script. When PHP runs as a server module, any number of scripts may share the same process ID, so it is not necessarily a unique number.
Returns the protocol number associated with name in /etc/protocols.
Returns the protocol name associated with protocol in /etc/protocols.
Returns the largest value that can be returned by rand( ).
Returns an associative array of information describing the resources being used by the process running the current script. If who is specified and is equal to 1, information about the process's children is returned. A list of the keys and descriptions of the values can be found under the getrusage(2) Unix command.
Returns the port associated with service in /etc/services. protocol must be either TCP or UDP.
Returns the service name associated with port and protocol in /etc/services. protocol must be either TCP or UDP.
Returns an associative array containing information about the current time, as obtained through gettimeofday(2). The array contains the following keys and values:
Returns a string description of the type of value. The possible values for value are "boolean", "integer", "double", "string", "array", "object", "resource", "NULL", and "unknown type".
Returns a formatted string for a timestamp date and time. Identical to date( ), except that it always uses Greenwich Mean Time (GMT), rather than the time zone specified on the local machine.
Returns a timestamp date and time value from the provided set of values. Identical to mktime( ), except that the values represent a GMT time and date, rather than one in the local time zone.
Formats a GMT timestamp. See strftime for more information on how to use this function.
Sends header as a raw HTTP header string; must be called before any output is generated (including blank lines, a common mistake). If the header is a Location header, PHP also generates the appropriate REDIRECT status code. If replace is specified and false, the header does not replace a header of the same name; otherwise, the header replaces any header of the same name.
Returns true if the HTTP headers have already been sent. If they have not yet been sent, the function returns false.
Converts the logical Hebrew text string to visual Hebrew text. If the second parameter is specified, each line will contain no more than size characters; the function attempts to avoid breaking words.
Performs the same function as hebrev( ), except that in addition to converting string, newlines are converted to <br>\n. If specified, each line will contain no more than size characters; the function attempts to avoid breaking words.
Prints a syntax-colored version of the PHP source file filename using PHP's built-in syntax highlighter. Returns true if filename exists and is a PHP source file; otherwise, returns false.
Prints a syntax-colored version of the string source using PHP's built-in syntax highlighter. Returns true if successful; otherwise, returns false.
Converts hex to its decimal value. Up to a 32-bit number, or 2,147,483,647 decimal (0x7FFFFFFF hexadecimal), can be converted.
Converts all characters in string that have special meaning in HTML and returns the resulting string. All entities defined in the HTML standard are converted. If supplied, style determines the manner in which quotes are translated. The possible values for style are:
Converts characters in string that have special meaning in HTML and returns the resulting string. A subset of all HTML entities covering the most common characters is used to perform the translation. If supplied, style determines the manner in which quotes are translated. The characters translated are:
The possible values for style are:
Sets whether the client disconnecting from the script should stop processing of the PHP script. If ignore is true, the script will continue processing, even after a client disconnect. Returns the current value; if ignore is not given, the current value is returned without a new value being set.
Returns a string created by joining every element in strings with separator.
Imports GET, POST, and cookie variables into the global scope. The types parameter defines which variables are imported, and in which order the three types are "g" or "G", "p" or "P", and "c" or "C". For example, to import POST and cookie variables, with cookie variables overwriting POST variables, types would be "cp". If given, the variable names are prefixed with prefix. If prefix is not specified or is an empty string, a notice-level error is sent due to the possible security hazard.
Returns true if the given value exists in the array. If the third argument is provided and is true, the function will return true only if the element exists in the array and has the same type as the provided value (that is, "1.23" in the array will not match 1.23 as the argument). If the argument is not found in the array, the function returns false.
This function is an alias for ini_set( ).
Returns the value for the configuration option variable. If variable does not exist, returns false.
Restores the value for the configuration option variable. This is done automatically when a script completes execution for all configuration options set using ini_set( ) during the script.
Sets the configuration option variable to value. Returns the previous value if successful or false if not. The new value is kept for the duration of the current script and is restored after the script ends.
Returns the integer value for value using the optional base base (if unspecified, base 10 is used). If value is a nonscalar value (object or array), the function returns 0.
Converts a dotted (standard format) IP address to an IPv4 address.
Parses the IPTC (International Press Telecommunications Council) data block data into an array of individual tags with the tag markers as keys. Returns false if an error occurs or if no IPTC data is found in data.
Returns true if value is an array; otherwise, returns false.
Returns true if value is a Boolean; otherwise, returns false.
Returns true if path exists and is a directory; otherwise, returns false. This information is cached; you can clear the cache with clearstatcache( ).
Returns true if value is a double; otherwise, returns false.
Returns true if path exists and is executable; otherwise, returns false. This information is cached; you can clear the cache with clearstatcache( ).
Returns true if path exists and is a file; otherwise, returns false. This information is cached; you can clear the cache with clearstatcache( ).
This function is an alias for is_double( ).
This function is an alias for is_long( ).
This function is an alias for is_long( ).
Returns true if path exists and is a symbolic link file; otherwise, returns false. This information is cached; you can clear the cache with clearstatcache( ).
Returns true if value is an integer; otherwise, returns false.
Returns true if value is null that is, is the keyword NULL; otherwise, returns false.
Returns true if value is an integer, a floating-point value, or a string containing a number; otherwise, returns false.
Returns true if value is an object; otherwise, returns false.
Returns true if path exists and is readable; otherwise, returns false. This information is cached; you can clear the cache with clearstatcache( ).
This function is an alias for is_double( ).
Returns true if value is a resource; otherwise, returns false.
Returns true if value is a scalar value an integer, Boolean, floating-point value, resource, or string. If value is not a scalar value, the function returns false.
Returns true if value is a string; otherwise, returns false.
Returns true if object is an instance of the class class or is an instance of a subclass of class. If not, the function returns false.
Returns true if path exists and was uploaded to the web server using the file element in a web page form; otherwise, returns false. See Chapter 7 for more information on using uploaded files.
Returns true if path exists and is a directory; otherwise, returns false. This information is cached; you can clear the cache with clearstatcache( ).
This function is an alias for is_writable( ).
Returns true if value, a variable, has been set; if the variable has never been set, or has been unset( ), the function returns false. |