A.2b. Alphabetical Listing of PHP Functions (f-i)
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 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.
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.
bool fputs(int handle, string string[, int length])
| |
This function is an alias for fwrite( ).
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
|
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 gethostbyname(string host)
| |
Returns the IP address for host. If no
such host exists, host is returned.
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 gmstrftime(string format[, int timestamp])
| |
Formats a GMT timestamp. See strftime for more
information on how to use this function.
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.
string ini_alter(string variable, string value)
| |
This function is an alias for ini_set( ).
 |  |  | A.2a. Alphabetical Listing of PHP Functions |  | A.2c. Alphabetical Listing of PHP Functions |
Copyright © 2003 O'Reilly & Associates. All rights reserved.
|