A.2b. Alphabetical Listing of PHP Functions (f-i)
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.
array fgetcsv(int handle, int length[, string delimiter])
| |
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);
string fgets(int handle, int length)
| |
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.
string fgetss(int handle, int length[, string tags])
| |
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.
array file(string path[, int include])
| |
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.
bool file_exists(string path)
| |
Returns true if the file at
path exists and false
if not.
int fileatime(string path)
| |
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(
).
int filectime(string path)
| |
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(
).
int filegroup(string path)
| |
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(
).
int fileinode(string path)
| |
Returns the inode number of the file path,
or false if an error occurs. This information is
cached; see clearstatcache.
int filemtime(string path)
| |
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( ).
int fileowner(string path)
| |
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( ).
int fileperms(string path)
| |
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( ).
int filesize(string path)
| |
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( ).
string filetype(string path)
| |
Returns the type of file given in path.
The possible types are:
fifo
|
The file is a fifo pipe.
|
char
|
The file is a text file.
|
dir
|
path is a directory.
|
block
|
A block reserved for use by the filesystem.
|
link
|
The file is a symbolic link.
|
file
|
The file contains binary data.
|
unknown
|
The file's type could not be determined.
|
bool flock(int handle, int operation[, int would_block])
| |
Attempts to lock the file path of the file specified by
handle. The operation is one of the
following values:
LOCK_SH
|
Shared lock (reader)
|
LOCK_EX
|
Exclusive lock (writer)
|
LOCK_UN
|
Release a lock (either shared or exclusive)
|
LOCK_NB
|
Add to LOCK_SH or LOCK_EX to
obtain a non-blocking lock
|
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.
double floor(double number)
| |
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.
int fopen(string path, string mode[, bool include])
| |
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:
r
|
Open the file for reading; file pointer will be at beginning of file.
|
r+
|
Open the file for reading and writing; file pointer will be at
beginning of file.
|
w
|
Open the 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.
|
w+
|
Open the file for reading and writing. If the file exists, it will be
truncated to zero length; if the file doesn't
already exist, it will be created. The file pointer starts at the
beginning of the file.
|
a
|
Open the file for writing. If the file exists, the file pointer will
be at the end of the file; if the file does not exist, it is created.
|
a+
|
Open the file for reading and writing. If the file exists, the file
pointer will be at the end of the file; if the file does not exist,
it is created.
|
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.
int fpassthru(int handle)
| |
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.
bool fputs(int handle, string string[, int length])
| |
This function is an alias for fwrite( ).
string fread(int handle, int length)
| |
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.
mixed fscanf(int handle, string format[, string name1[, ... string nameN]])
| |
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.
int fseek(int handle, int offset[, int from])
| |
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:
SEEK_SET
|
Sets the file pointer to the byte offset
(the default)
|
SEEK_CUR
|
Sets the file pointer to the current location plus
offset bytes
|
SEEK_END
|
Sets the file pointer to EOF minus offset
bytes
|
This function returns 0 if the function was
successful and -1 if the operation failed.
int fsockopen(string host, int port[, int error[, string message[, double timeout]]])
| |
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:
dev (0)
|
The device on which the file resides
|
ino (1)
|
The file's inode
|
mode (2)
|
The mode with which the file was opened
|
nlink (3)
|
The number of links to this file
|
uid (4)
|
The user ID of the file's owner
|
gid (5)
|
The group ID of the file's owner
|
rdev (6)
|
The device type (if the file is on an inode device)
|
size (7)
|
The file's size (in bytes)
|
atime (8)
|
The time of last access (in Unix timestamp format)
|
mtime (9)
|
The time of last modification (in Unix timestamp format)
|
ctime (10)
|
The time the file was created (in Unix timestamp format)
|
blksize (11)
|
The blocksize (in bytes) for the filesystem
|
blocks (12)
|
The number of blocks allocated to the file
|
Returns the byte offset to which the file referenced by
handle is set. If an error occurs, returns
false.
int ftruncate(int handle, int length)
| |
Truncates the file referenced by handle to
length bytes. Returns
true if the operation is successful and
false if not.
mixed func_get_arg(int index)
| |
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.
bool function_exists(string function)
| |
Returns true if a function with
function has been defined, and
false otherwise. The comparison to check for a
matching function is case-insensitive.
int fwrite(int handle, string string[, int length])
| |
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.
string get_browser([string name])
| |
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.
string get_cfg_var(string name)
| |
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.
string get_class(object object)
| |
Returns the name of the class of which the given object is an
instance. The class name is returned as a lowercase string.
array get_class_methods(mixed class)
| |
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.
array get_class_vars(string class)
| |
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.
string get_current_user( )
| |
Returns the name of the user under whose privileges the current PHP
script is executing.
array get_declared_classes( )
| |
Returns an array containing the name of each defined class. This
includes any classes defined in extensions currently loaded in PHP.
array get_defined_constants( )
| |
Returns an associative array of all constants defined by extensions
and the define( ) function and their values.
array get_defined_functions( )
| |
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.
array get_defined_vars( )
| |
Returns an array of all defined environment, server, and user-defined
variables.
array get_extension_funcs(string name)
| |
Returns an array of functions provided by the extension specified by
name.
get_html_translation_table | |
array get_html_translation_table([int which[, int style]])
| |
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:
ENT_COMPAT (default)
|
Converts double quotes, but not single quotes
|
ENT_NOQUOTES
|
Does not convert either double quotes or single quotes
|
ENT_QUOTES
|
Converts both single and double quotes
|
array get_included_files( )
| |
Returns an array of the files included into the current script by
include( ), include_once( ),
require( ), and require_once(
).
array get_loaded_extensions( )
| |
Returns an array containing the names of every extension compiled and
loaded into PHP.
bool get_magic_quotes_gpc( )
| |
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.
array get_meta_tags(string path[, int include])
| |
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.
array get_object_vars(object object)
| |
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.
string get_parent_class(mixed object)
| |
Returns the name of the parent class for the given object. If the
object does not inherit from another class, returns an empty string.
array get_required_files( )
| |
This function is an alias for get_included_files(
).
string get_resource_type(resource handle)
| |
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.
array getdate([int timestamp])
| |
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:
seconds
|
Seconds
|
minutes
|
Minutes
|
hours
|
Hours
|
mday
|
Day of the month
|
wday
|
Numeric day of the week (Sunday is
"0")
|
mon
|
Month
|
year
|
Year
|
yday
|
Day of the year
|
weekday
|
Name of the day of the week
("Sunday" through
"Saturday")
|
month
|
Name of the month ("January"
through "December")
|
string getenv(string name)
| |
Returns the value of the environment variable
name. If name
does not exist, getenv( ) returns
false.
string gethostbyaddr(string address)
| |
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.
string gethostbyname(string host)
| |
Returns the IP address for host. If no
such host exists, host is returned.
array gethostbynamel(string host)
| |
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.
int getmxrr(string host, array hosts[, array weights])
| |
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.
int getprotobyname(string name)
| |
Returns the protocol number associated with
name in
/etc/protocols.
string getprotobynumber(int protocol)
| |
Returns the protocol name associated with
protocol in
/etc/protocols.
Returns the largest value that can be returned by rand(
).
array getrusage([int who])
| |
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.
int getservbyname(string service, string protocol)
| |
Returns the port associated with service
in /etc/services.
protocol must be either TCP or UDP.
string getservbyport(int port, string protocol)
| |
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:
sec
|
The current number of seconds since the Unix epoch.
|
msec
|
The current number of microseconds to add to the number of seconds.
|
minuteswest
|
The number of minutes west of Greenwich the current time zone is.
|
dsttime
|
The type of Daylight Savings Time correction to apply (during the
appropriate time of year, a positive number if the time zone observes
Daylight Savings Time).
|
string gettype(mixed value)
| |
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".
string gmdate(string format[, int timestamp])
| |
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.
int gmmktime(int hour, int minutes, int seconds, int month, int day, int year)
| |
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.
string gmstrftime(string format[, int timestamp])
| |
Formats a GMT timestamp. See strftime for more
information on how to use this function.
void header(string header[, bool replace])
| |
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.
string hebrev(string string[, int size])
| |
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.
string hebrev(string string[, int size])
| |
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.
bool highlight_file(string filename)
| |
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.
bool highlight_string(string source)
| |
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.
string htmlentities(string string[, int style)
| |
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:
ENT_COMPAT (default)
|
Converts double quotes, but not single quotes
|
ENT_NOQUOTES
|
Does not convert either double quotes or single quotes
|
ENT_QUOTES
|
Converts both single and double quotes
|
string htmlspecialchars(string string[, int style])
| |
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:
-
Ampersand (&) becomes
&
-
Double quotes (") become
"
-
Single quote (') becomes
'
The possible values for style are:
ENT_COMPAT (default)
|
Converts double quotes, but not single quotes
|
ENT_NOQUOTES
|
Does not convert either double quotes or single quotes
|
ENT_QUOTES
|
Converts both single and double quotes
|
int ignore_user_abort([bool ignore])
| |
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.
string implode(array strings, string separator)
| |
Returns a string created by joining every element in
strings with
separator.
bool import_request_variables(string types[, string prefix])
| |
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.
bool in_array(mixed value, array array[, bool strict])
| |
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.
string ini_alter(string variable, string value)
| |
This function is an alias for ini_set( ).
string ini_get(string variable)
| |
Returns the value for the configuration option
variable. If
variable does not exist, returns
false.
string ini_restore(string variable)
| |
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.
string ini_set(string variable, string value)
| |
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.
int intval(mixed value[, int base])
| |
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.
int ip2long(string address)
| |
Converts a dotted (standard format) IP address to an IPv4 address.
array iptcparse(string data)
| |
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.
bool is_array(mixed value)
| |
Returns true if value
is an array; otherwise, returns false.
bool is_bool(mixed value)
| |
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( ).
bool is_double(mixed value)
| |
Returns true if value
is a double; otherwise, returns false.
bool is_executable(string path)
| |
Returns true if path
exists and is executable; otherwise, returns
false. This information is cached; you can clear
the cache with clearstatcache( ).
bool is_file(string path)
| |
Returns true if path
exists and is a file; otherwise, returns false.
This information is cached; you can clear the cache with
clearstatcache( ).
bool is_float(mixed value)
| |
This function is an alias for is_double( ).
This function is an alias for is_long( ).
bool is_integer(mixed value)
| |
This function is an alias for is_long( ).
bool is_link(string path)
| |
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( ).
bool is_long(mixed value)
| |
Returns true if value
is an integer; otherwise, returns false.
bool is_null(mixed value)
| |
Returns true if value
is null—that is, is the keyword NULL;
otherwise, returns false.
bool is_numeric(mixed value)
| |
Returns true if value
is an integer, a floating-point value, or a string containing a
number; otherwise, returns false.
bool is_object(mixed value)
| |
Returns true if value
is an object; otherwise, returns false.
bool is_readable(string path)
| |
Returns true if path
exists and is readable; otherwise, returns false.
This information is cached; you can clear the cache with
clearstatcache( ).
bool is_real(mixed value)
| |
This function is an alias for is_double( ).
bool is_resource(mixed value)
| |
Returns true if value
is a resource; otherwise, returns false.
bool is_scalar(mixed value)
| |
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.
bool is_string(mixed value)
| |
Returns true if value
is a string; otherwise, returns false.
bool is_subclass_of(object object, string class)
| |
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.
bool is_uploaded_file(string path)
| |
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.
bool is_writable(string path)
| |
Returns true if path
exists and is a directory; otherwise, returns
false. This information is cached; you can clear
the cache with clearstatcache( ).
bool is_writeable(string path)
| |
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.
| | | A.2a. Alphabetical Listing of PHP Functions | | A.2c. Alphabetical Listing of PHP Functions |
Copyright © 2003 O'Reilly & Associates. All rights reserved.
|