Book HomeMySQL and mSQLSearch this book

Chapter 18. PHP and Lite Reference

Contents:

PHP
Lite

18.1. PHP

The following is the quick reference guide to PHP. This list is complete as of PHP 3. The functions that work with MySQL and mSQL are covered, but those specific to other database servers -- such as Ababas D, dbm, Oracle, and PostgreSQL -- are omitted.

abs

$pos_num = abs($number);

Returns the absolute value of number.

addslashes

$escaped_string = addslashes($string);

Returns a copy of string with any $ \ or ' characters escaped.

asort

$sorted_array = asort($array);

Returns a sorted copy of the associative array array. asort works only on associative arrays. Use sort to sort regular arrays. If the first member of the array is a number the returned array will be sorted numerically, otherwise the returned array will be sorted alphabetically.

bindec

$decimal = bindec($binary);

Returns the decimal equivalent of binary.

ceil

$higher_integer = ceil($number);

Rounds number to the next highest integer and returns that as a floating point value.

chdir

chdir($directory);

Changes the current working directory to directory.

chgrp

chgrp($file,$group);

Changes the file file to belong to the group group.

chimed

chimed($file,$permissions);

Changes the file to have the permissions permissions. The permissions argument must be given as an octal value.

chown

chown($file, $owner);

Changes the file to belong to the owner owner. This function takes effect only if the PHP binary is running as root, which is not generally recommended.

chop

$stripped_string = chop($string);

Returns string with all trailing new lines, spaces, and tabs removed.

chr

$character = chr($number);

Returns the character that corresponds to the ASCII value of number. Hexadecimal and octal numbers are denoted with the usual 0xff and 077 respectively. All other numbers are considered decimal.

clearstack

clearstack();

Empties the current stack. This function is a kludge designed to circumvent a limitation in the design of PHP. If you have a user-defined function that contains a large loop, you may run into stack space problems. If this happens, call this function inside the loop. The drawback of doing this is that your function cannot be called within another function. The output of your function has to be saved to a variable which then can be used as you wish.

clearstatcache

clearstatcache();

Empties the cache used for any functions that access information about files. Because accessing file information can take a relatively long time, this information is stored in a cache by PHP. If you want to be sure you are getting the most current (i.e., noncached) information about a file, call this function before retrieving the information.

closedir

closedir($directory);

Closes a directory opened with opendir.

closelog

closelog();

Stops all logging done via syslog.

cos

$result = cos($number);

Returns the cosine of number.

count

$number = count($array);

Returns the number of elements in array. If array is a nonarray variable, the function returns 1 (because a variable looks like an array with only one element). If array is not defined, is returned.

crypt

$encrypted_string = crypt($string);
$encrypted_string = crypt($string, $salt);

Returns an encrypted version of string. The encryption is the standard Unix DES encryption as used in Unix passwords and the like. An optional two-character salt can be provided.

date

$formatted_date = date($format,$time);

Returns time (a standard Unix time as given by the Time function) formatted with format. The returned value is the same as format except that the following characters are replaced with the appropriate value:

A

AM/PM

a

am/pm

D

Day (eg., Sun)

d

Day (eg., 13)

F

Month (eg., February)

H

Hours in 24 hour format (eg., 17)

h

Hours in 12 hour format (eg., 5)

i

Minutes (eg., 30)

l

Day (eg., Sunday)

M

Month (eg., Feb)

m

Month (eg., 02)

s

Seconds (eg., 27)

Y

Year (eg., 1998)

y

Year (eg., 98)

U

Seconds since epoch (eg., 803537321)

z

Day of the year (eg., 154)

dblist

$db_info = dblist();

Returns a list of the databases supported by PHP.

decbin

$binary = decbin($decimal);

Returns the binary equivalent of decimal.

dexhex

$hex = dechex($decimal);

Returns the hexadecimal equivalent of decimal.

decoct

$octal = decoct($decimal);

Returns the octal equivalent of decimal.

doubleval

$double = doubleval($variable);

Returns variable as a floating point number.

echo

echo [format_string] expression [, expression ...]

This is not a true function but rather PHP's built-in version of the C printf function. In its simplest form, echo simply prints out expression. Up to 5 expressions can be given, each of which are printed out in turn. In addition, a format string can be provided. The format string is in the same style as C or Perl's printf function.

end

end($array);

Sets the internal pointer of array to the end of the array.

ereg

$result = ereg($expression, $string);

$result = ereg($expression, $string, $match_array);

Returns a true value if string matches the regular expression expression. If an array is provided as the third argument, the values matched in the string are placed in the array.

eregi

$result = eregi($expression, $string);
$result = eregi($expression, $string, $match_array);

Identical to ereg except that case is ignored for the purposes of matching.

ereg_replace

ereg_replace($expression, $replacement_string, $string);

Replaces all parts of string that match expression with replacement_string.

eregi_replace

eregi_replace($expression, $replacement_string, $string);

Identical to ereg_replace except that case is ignored for the purposes of matching.

escapeshellcmd

$safe_string = escapeshellcmd($string);

Returns a copy of string with its characters escaped so that it is safe for use with exec or system.

eval

eval($string);

Evaluates the contents of string as if it were a PHP script. Variable substitution is done on the string so if you want to use a variable in the "miniscript" you should escape it.

exec

$last_line = exec($command);
$last_line = exec($command, $output_array);
$last_line = exec($command, $output_array, $return_code);

$last_line = exec($command, $output_array);

Executes command as a Unix command in a subshell. Only the last line of the command output is returned. If an array is provided as the second argument, all of the lines of output from the command are placed in the array. If a third argument is present, the return code from the command is placed in that variable.

exit

exit();

Ends all parsing of the HTML file.

exp

$result = exp($number);

Returns the number e raised to the number power.

fclose

fclose($fd);

Closes a file opened by fopen.

feof

$result = feof($fd);

Returns true if the file descriptor fd is at the end of the file.

fgets

$line = fgets($fd, $max_bytes);

Returns the next line (up to max_bytes in length) from the file referred to by fd.

fgetss

$line = fgetss($fd, $max_bytes);

Identical to fgets except that it attempts to strip all HTML and PHP tags from the input.

file

$array = file($filename);

Returns an array containing every line in the file filename.

fileatime

$time = fileatime($filename);

Returns (in standard Unix time format) the last time filename was accessed. If this information cannot be obtained for whatever reason, the function returns -1.

filectime

$time = filectime($filename);

Returns (in standard Unix time format) the last time filename's status was changed. If this information cannot be obtained for whatever reason, the function returns -1.

filegroup

$group_id = filegroup($filename);

Returns the group ID of filename's group. If this information cannot be obtained for whatever reason, the function returns -1.

fileinode

$inode = fileinode($filename);

Returns the inode of filename. If this information cannot be obtained for whatever reason, the function returns -1.

filemtime

$time = filemtime($filename);

Returns (in standard Unix time format) the last time filename was modified. If this information cannot be obtained for whatever reason, the function returns -1.

fileowner

$owner = fileowner($filename);

Returns the ID of the owner of the file. If this information cannot be obtained for whatever reason, the function returns -1.

fileperms

$permissions = fileperms($filename);

Returns the permissions of filename. If this information cannot be obtained for whatever reason, the function returns -1.

filesize

$size = filesize($filename);

Returns the size of filename in bytes. If this information cannot be obtained for whatever reason, the function returns -1.

filetype

$type = filetype($filename);

Returns one of the following, indicating the type of filename: dir, file, fifo, char, block, or link.

floor

$lower_integer = floor($number);

Rounds number to the next lowest integer and returns that as a floating point value.

flush

flush();

Flushes the buffer on the standard output so that the end user immediately sees all of the output so far.

fopen

$fd = fopen($filename, $mode);

Opens the file filename in the mode mode and returns a file descripter associated with the open file. As with the C function fopen, the mode is one of "r", "r+", "w", "w+", "a", "a+". The function returns -1 if the file could not be opened.

fputs

fputs($fd, $string);

Writes string to the file associated with fd, followed by a newline.

fpassthru

fpassthru($fd);

Directly prints all of the remaining data in the file associated with fd.

fseek

fseek($fd, $position);

Positions the file associated with fd to position bytes from the beginning of the file.

fsockopen

$fd = fsockopen($hostname,$port);

Opens a connection with hostname on port port and returns a file descriptor associated with the open connection. If the port number is 0, the hostname will be considered the filename of a Unix-style socket file on the local host. In the case of an error, the function returns the following: -3 if the socket could not be created, -4 if the hostname could not be resolved, -5 if the connection was refused or timed out, -6 if the fdopen() call failed, or -7 if the setvbuf() call failed.

ftell

$position = ftell($fd);

Returns the position of the pointer in the file associated with fd. This value can be used as an argument to fseek.

getaccdir

$directory = getaccdir();

Returns the directory where the PHP configuration files are held.

getenv

$value = getenv($variable);

Returns the value of the environment variable variable.

gethostbyname

$address = gethostbyname($hostname);

Returns the IP address of hostname.

gethostbyaddr

$hostname = gethostbyaddr($address);

Returns the hostname of the machine with the IP address address.

getimagesize

$file_info_array = getimagesize($filename);

Returns an array of information about the image in the file filename. The first element of the array is the width of the image, the second is the height, and the third is the type of the image. GIF, JPG, and PNG images are currently recognized. The fourth element is a string of the format "width=xxx height=yyy" which can be used directly in an HTML <IMG> tag.

getlastaccess

$time = getlastaccess();

Returns (in standard Unix time format) the date and time the page was last accessed. This function works only if PHP was compiled with access logging enabled.

getlastbrowser

$browser = getlastbrowser();

Returns the identification string of the last browser to access the page. This function works only if PHP was compiled with access logging enabled.

getlastemail

$email = getlastemail();

Returns the e-mail address of the last person to access the page. This function works only if PHP was compiled with access logging enabled.

getlasthost

$host = getlasthost();

Returns the hostname of the last machine to access the page. This function works only if PHP was compiled with access logging enabled.

getlastmod

$time = getlastmod();

Returns the time (in standard Unix time format) that the page was last modified. This function works only if PHP was compiled with access logging enabled.

getlastref

$url = getlastref();

Returns the URL of the referring page of the last visitor to the page. This function works only if PHP was compiled with access logging enabled.

getlogdir

$directory = getlogdir();

Returns the directory that contains the PHP log files.

getmyinode

$inode = getmyinode();

Returns the inode of the HTML file that contains the current PHP script.

getmypid

$pid = getmypid();

Returns the process ID number of the current PHP process.

getmyuid

$id = getmyuid();

Returns the user ID of the owner of the HTML file that contains the current PHP script.

getrandmax

$number = getrandmax();

Returns the largest possible number that will be returned by rand.

getstartlogging

$time = getstartlogging();

Returns the time (in standard Unix format) that logging began on the HTML file containing the current PHP script.

gettoday

$hits = gettoday();

Returns the number of hits the page has received since midnight at the beginning of the current day.

gettotal

$hits = gettotal();

Returns the total number of hits the page has received since logging was started on the page.

gettype

$type = gettype($variable);

Returns one of "integer," "double," or "string," indicating the type of variable.

gmdate

$formatted_date = gmdate($format, $time);

Identical to Date except that it uses Greenwich Mean time to calculate the values instead of the local time.

header

header($header_string);

Outputs header_string as the HTTP header of the document. This function must be used before any HTML in the file and before any PHP commands which generate output.

hexdec

$decimal = hexdec($hex);

Returns the decimal equivalent of hex.

htmlspecialchars

$html_string = htmlspecialchars($string);

Returns string, replacing any special characters (including <, >, &, " and all ASCII characters from 160 to 255) with their HTML entity codes.

imagearc

imagearc($image, $cx, $cy, $width, $height, $start, $end, $color);

Draws a partial ellipse in image with the color color. The ellipse has the center (cx, cy) width width, height height, begins at start degrees, and ends at end degrees.

imagechar

imagechar($image, $size, $x, $y, $character, $color);

Draws character in image with the color color with the font size size. The top left of character is at the point (x, y).

imagecharup

imagecharup($image, $size, $x, $y, $character, $color);

Identical to imagechar except that the character is drawn vertically with the bottom left at (x, y).

imagecolorallocate

$color = imagecolorallocate($image, $red, $green, $blue);

Returns a color for use with the image image using the RGB components specified.

imagecolortransparent

imagecolortransparent($image, $color);

Sets color as the transparent color for image.

imagecopyresized

imagecopyresized($dest_image, $src_image, $dest_x, $dest_y, $src_x, $src_y,
   $dest_width, $dest_heigth, $src_width, $src_heigth);

Copies a rectangular portion from src_image and pastes it into dest_image, resizing if necessary. The arguments dest_x and dest_y are the coordinates of the top left of the rectangle for the destination image, and dest_height and dest_width are the height and width. The arguments src_x, src_y, src_width, and src_heigth are the corresponding values for the source image.

imagecreate

$image = imagecreate($width, $height);

Returns an image indentifier representing a new image with the specified height and width.

imagecreatefromgif

$image = imagecreatefromgif($filename);

Returns an image indentifier representing the image contained in the file filename.

imagedestroy

imagedestroy($image);

Frees any resources occupied by image.

imagefill

imagefill($image, $x, $y, $color);

Flood fills image with the color color starting at the point (x, y).

imagefilledpolygon

imagefilledpolygon($image, $points_array, $num_points, $color);

Creates a polygon in image filled with the color color. The second argument is an array of the points of the polygon. The first two elements of the array are the x and y values of the first point. The next two elements are the value of the next point, and so on. The third argument is the number of points in the polygon.

imagefilledrectangle

imagefilledrectangle($image, $x1, $y1, $x2, $y2, $color);

Creates a rectangle in image filled with the color color. The arguments x1 and y1 form the top left point of the rectangle and x2 and y2 form the bottom right.

imagefilltoborder

imagefilltoborder($image, $x, $y, $border, $color);

Identical to imagefill except that the fill stops where the color border is encountered.

imagegif

imagegif($image);

imagegif($image, $filename);

Outputs the contents of image as a GIF image. If a second argument is present the GIF is written to that filename, otherwise the output is sent straight to the browser.

imageinterlace

imageinterlace($image, $interlace);

Toggles the interlace bit of image to the value of interlace, which should be 1 (for on) or (for off).

imageline

imageline($image, $x1, $y1, $x2, $y2, $color);

Creates a line in image of color color from the point (x1, y2) to (x2, y2).

imagepolygon

imagepolygon($image, $points, $numpoints, $color);

Identical to imagefilledpolygon except that the polygon is not filled.

imagerectangle

imagerectangle($image, $x1, $y1, $x2, $y2, $color);

Identical to imagefilledrectangle except that the rectangle is not filled.

imagesetpixel

imagesetpixel($image, $x, $y, $color);

Draws a single point on image at (x, y) of color color.

imagestring

imagestring($image, $size, $x, $y, $string, $color);

Identical to imagechar except that it outputs the entire string string.

imagestringup

imagestringup($image, $size, $x, $y, $string, $color);

Identical to imagecharup except that it outputs the entire string string.

imagesx

$x_size = imagesx($image);

Returns the width of image in pixels.

imagesy

$y_size = imagesy($image);

Returns the height of image in pixels.

include

include($filename);

Includes the file filename in the current page. Full PHP parsing is done on the included file. PHP searches each of the directories in the environment variable PHP_INCLUDE_PATH for filename.

initsyslog

initsyslog();

Prepares the system for syslog logging. After calling this function you can use syslog to generate log entries.

intval

$integer = intval($variable);

Returns the contents of variable as an integer.

isset

$defined = isset($variable);

Returns 1 if variable is defined, 0 otherwise.

key

$key = key($array);

Returns the key of the next element in array. For an associative array, it returns the name of the key. For a regular array it returns the number of the element.

link

link($target, $filename);

Creates a hard link from filename to target.

linkinfo

$info = linkinfo($filename);

Returns a true value if the link filename exists (but not necessarily the file to which the link points). The function returns -1 in case of an error.

log

$result = log($number);

Returns the natural logarithm of number.

log10

$result = log10($number);

Returns the base 10 logarithm of number.

logas

logas($filename);

Logs the hit on the current page as a hit on filename instead of the filename of the page.

mail

mail($to, $subject, $message);

mail($to, $subject, $message, $headers);

Sends an e-mail message to to with the subject subject and message as the body, If a forth argument is provided it is appended to the headers of the message.

max

$maximum = max($array);

Returns the largest value in array. If array contains strings, it returns the element that is last alphabetically.

md5

$hash = md5($string);

Returns the MD5 hash of string.

microtime

$ms = microtime();

Returns a string that contains the fractional part of the current second (expressed as a decimal) followed by the standard Unix time.

min

$minimum = min($array);

Returns the minimum value in array. If array contains strings, it returns the element that is first alphabetically.

mkdir

mkdir($directory, $mode);

Creates the directory directory with the given mode. The mode must be an octal value.

mktime

$time = mktime($hour,$minute,$second,$month,$day,$year);

Returns a time in standard Unix time format based on the parameters given. If there are less than six parameters, the rightmost parameters are assumed to be the current value (e.g., if four parameters are given, the current day and year are used).

msql

mysql

$result = msql($database, $query);
$result = mysql($database, $query);

Sends the query query to the mSQL/MySQL database database. For a non-SELECT statement the function returns for mSQL 1.x and MySQL and the number of affected rows for mSQL 2.x. For a SELECT statement the function returns a result identifier to be used with other msql_* functions. In the case of an error the function returns -1.

mysql_affected_rows

$num_rows = mysql_affected_rows();

Returns the number of rows affected by the last INSERT, UPDATE, or DELETE statement.

msql_close

mysql_close

msql_close(); 
mysql_close();

Closes the connection to the mSQL/MySQL database server.

msql_connect

mysql_connect

msql_connect($hostname);
mysql_connect($hostname);
mysql_connect($hostname, $username);
mysql_connect($hostname, $username, $password);

Creates a connection with the mSQL/MySQL database server at hostname. A connection to the server on the local host is made with m(y)sql_connect("localhost"). If no connection exists at the time of the first call to m(y)sql, a connection is automatically made to the localhost. With MySQL an optional username or username/password combination may be given. If PHP is being run in its enhanced security mode (called SAFE MODE), the username must be either the owner of the HTML document or the owner of the web server process.

msql_createdb

mysql_createdb

msql_createdb($database);
mysql_createdb($database);

Creates the given database.

msql_dbname

mysql_dbname

$db = msql_dbname($result, $i);
$db = mysql_dbname($result, $i);

Returns the name of the database stored in the ith field of the result returned by a call to m(y)sql_listdbs.

msql_dropdb

mysql_dropdb

msql_dropdb($database);
mysql_dropdb($database);

Removes database and all tables within it.

msql_fieldflags

mysql_fieldflags

$flags = msql_fieldflags($result, $i);
$flags = mysql_fieldflags($result, $i);

Returns the flags belonging to the ith field of result. The returned value can be one of "primary key", "not null", "not null primary key" or "".

msql_fieldlen

mysql_fieldlen

$length = msql_fieldlen($result, $i);
$length = mysql_fieldlen($result, $i);

Returns the length of the ith field of result.

msql_fieldname

mysql_fieldname

$name = msql_fieldname($result, $i);
$name = mysql_fieldname($result, $i);

Returns the column name of the ith field of result.

msql_fieldtype

mysql_fieldtype

$type = msql_fieldtype($result, $i);
$type = mysql_fieldtype($result, $i);

Returns the type of the ith of result (i.e. "char", "real", etc.).

msql_freeresult

mysql_freeresult

msql_freeresult($result);
mysql_freeresult($result);

Frees the memory associated with a mSQL/MySQL result. All memory is automatically freed at the end of the script, so use this function only if your script is taking up too much memory.

mysql_insert_id

$id_num = mysql_insert_id();

Returns the ID number used for the last INSERT statement that contained an auto_increment field.

msql_listdbs

mysql_listdbs

$result = msql_listdbs();
$result = mysql_listdbs();

Returns a result pointer containing the names of all of the databases available on the mSQL/MySQL server. The m(y)sql_dbname function can retrieve values from the pointer.

msql_listfields

mysql_listfields

$result = msql_listfields($database, $table);
$result = mysqllistfields($database, $table);

Returns a result pointer to information about the fields of the table table within database. The functions m(y)sql_fieldflags, m(y)sql_fieldlen, m(y)sql_fieldname, and m(y)sql_fieldtype can retrieve data from the pointer.

msql_listtables

mysql_listtables

$result = msql_listtables($database);
$result = mysql_listtables($database);

Returns a result pointer containing the names of all of the tables within database. The m(y)sql_tablename function can retrieves values from the pointer.

msql_numfields

mysql_numfields

$num_fields = msql_numfields($result);
$num_fields = mysql_numfields($result);

Returns the number of fields within result.

msql_numrows

msql_numrows

$num_rows = msql_numrows($result);
$num_rows = mysql_numrows($result);_

Returns the number of rows within result.

msql_regcase

$new_string = msql_regcase($string);

Returns a copy of string which has been transformed into a regular expression that will perform a case-insensitive match in a mSQL statement.

msql_result

mysql_result

$result_string = msql_result($result, $i, $field);
$result_string = mysql_result($result, $I, $field);

Returns an entry from the field field in the ith row of result. The argument field is the name of the field column and can be specified as table.field for results that involved joined tables. Any MySQL internal functions which can affect SELECT results can be included in the field argument, for instance, mysql_result $result, $i,"length($field)").

msql_tablename

mysql_tablename

$name = msql_tablename($result, $i);
$name = mysql_tablename($result, $i);

Returns the name of the table stored in the ith field of the result returned by a call to m(y)sql_listtables.

next

next($array);

Moves the pointer of array to the next element and returns that element.

octdec

$decimal = octdec($octal);

Returns the decimal equivalent of octal.

opendir

opendir($directory);

Opens a directory for use with the readdir function. You should close the directory with closedir when you are finished with it.

openlog

openlog($ident, $options, $facility);

Opens the system log for writing. This function should be called after initlog and before the first syslog call. The arguments are the same as the Unix openlog system call. The value of ident is prepended to each log message and is usually the name of the program. The value of options can be any of the following: LOG_CONS (log to the console if there is an error with the standard procedure), LOG_NDELAY (open the log connection immediately instead of at the time of the first log message), LOG_PERROR (log to stderr as well), LOG_PID (include the process PID with each log message). Options can be combined with bitwise OR (e.g. (LOG_DELAY|LOG_PERROR|LOG_PID)). Facility is one of the system-defined log levels (e.g. LOG_SYSLOG, LOG_USER, LOG_KERN, etc.).

ord

$number = ord($character);

Returns the ASCII value of character.

parse_str

parse_str($string);

Parses a URL encoded string of the format "variable1=value1&variable2=value2" and initializes variables with the appropriate values. The PHP program automatically performs this function with incoming form data at the beginning of every script.

passthru

passthru($command);
passthru($command, $return_value);

Executes the external command command and sends all of the output directory to the browser. If a second argument is present, the return value of the command is placed there.

pclose

pclose($fd);

Closes a pipe opened with popen.

phpinfo

phpinfo();

Prints an informational page that's useful when debugging the PHP setup. This is the same page that is printed if you add "?info" to any PHP URL, or if you access the PHP binary directly (i.e., http://www.myserver.com/cgi-bin/php).

phpversion

$version = phpversion();

Returns the version of PHP that is currently running.

popen

$fd = popen($command, $mode);

Runs the external command command and either sends data to the command (if mode is "w") or reads data from the command (if mode is "r"). You must close any file descriptors opened in this manner with pclose.

pos

$position = pos($array['element']);

Returns the numerical position of array['element'] within the associative array array.

pow

$result = pow($x, $y);

Returns x raised to the power y.

prev

$element = prev($array);

Moves the internal pointer of array to the previous element and returns that element.

putenv

putenv($string);

Puts string into the local environment. Note that the environment is destroyed at the end of the script, so this function is really useful only when external programs are called within the script.

quotemeta

$quoted_string = quotemeta($string);

Returns string with all special characters escaped so that it is safe to use within a regular expression.

rand

$number = rand();

Returns a random number between and the system-defined number RANDMAX. You should seed the random number generator with srand once and only once at the beginning of your script.

readdir

$file = readdir();

Returns the next directory entry in the current open directory and advances the directory pointer. Repeated calls to this function will return the next directory entry until there are no more left.

readfile

$filesize = readfile($filename);

Outputs the contents of filename directly to the browser and returns the size of the file. This function is safe to use on binary files such as images.

readlink

$filename = readline($link);

Returns the path of the real file referenced by link. In case of error the function returns -1.

reg_match

$result = reg_match($expression, $string);
$result = reg_match($expression, $string, $array);

Identical to ereg . This function is included only for backwards compatibility with older versions of PHP.

reg_replace

reg_replace($expression, $replacement, $string);

Identical to ereg_replace . This function is included only for backwards compatibility with older versions of PHP.

reg_search

$partial_string = reg_search($expression, $string);
$partial_string = reg_search($expression, $string, $array);

Identical to ereg except that the portion of string after the first match is returned. If there is no match, the function returns an empty string. This function is included only for backwards compatibility with older versions of PHP.

rename

rename($oldfile, $newfile);
Renames oldfile to anewfile.
reset

reset($array);

Moves the internal pointer of array to the first element and returns that element.

return

return($value);

Exits the current user-defined function and returns value.

rewind

rewind($fd);

Moves the file pointer for fd to the beginning of the file.

rewinddir

rewinddir();

Moves the current directory pointer to the beginning of the directory.

rmdir

rmdir($directory);

Deletes directory if it is empty.

rsort

$sorted_array = rsort($array)

Returns a sorted copy of the nonassociative array array in descending order. If the first member of the array is a number, the returned array will be sorted numerically, otherwise the returned array will be sorted alphabetically.

setcookie

setcookie($name);

setcookie($name, $value, $expire, $path, $domain, $secure);

Sends a cookie with the given attributes to the browser. If only name is present, that cookie with that name is deleted from the browser. Any argument may be left out or replaced with "" (or in the case of expire and secure) to be skipped.

seterrorreporting

seterrorreporting($value);

If value is 0, all errors will be disabled, otherwise errors are reported as normal.

setlogging

setlogging($value);

If value is nonzero, access logging for the current page will be enabled, otherwise it will be disabled.

setshowinfo

setshowinfo($value);

If value is nonzero, an informational footer will be printed at the bottom of the page.

settype

settype($variable, $type);

Sets the type of variable to type, which can be integer, double, or string.

shl

$value = shl($number, $b);

Returns the value of number shifted b bits to the left.

shr

$value = shr($number, $b);

Returns the value of number shifted b bits to the right.

sin

$value = sin($number);

Returns the sine of number (in radians).

sleep

sleep($seconds);

Stops the processing of the page for seconds seconds.

sort

$sorted_array = sort($array)

Returns a sorted copy of the nonassociative array array in ascending order. If the first member of the array is a number, the returned array will be sorted numerically, otherwise the returned array will be sorted alphabetically.

soundex

$soundex_key = soundex($string);

Returns the soundex key of string.

sprintf

$string = sprintf($format, $arg, [$arg, $arg, ...]);

Returns format with each C printf-style variable indicator replaced with the appropriate arg. Up to 5 arguments can be provided.

sqrt

$value = sqrt($number);

Returns the square root of number.

srand

srand($integer);

Seeds the random number generator with the value integer. This function should be called once and only once at the beginning of any script where you use the rand function.

strchr

strstr

$substring = strchr($string, $value);

$substring = strstr($string, $value);

Returns the portion of string that occurs starting after the first instance of value. The strchr and strstr functions are identical and are both included for the purposes of completeness.

strtr

strtr($string, $set1, $set2);

Translates all characters in string that are in set1 to the corresponding character in set2. If set1 is longer than set2, the last character in set2 is used for the extra characters in set1. If set2 is longer than set1, the extra characters in set2 are ignored.

stripslashes

$plain_string = stripslashes($escaped_string);

Removes all escape characters from escaped_string.

strlen

$length = strlen($string);

Returns the length of string.

strrchr

$substring = strrchr($string, $character);

Searches string backwards for character. The function returns the portion of string from the first occurrence of character it finds to the end of the string. An empty string is returned if character is not found.

strtok

$substring = strtok($string, $characters);

$substring = strtok($characters);

Splits string up into substrings using any of the characters in characters as delimiters. After the first call to strtok, omit the string argument in subsequent calls to return each successive substring until the end of string is reached.

strtolower

$lc_string = strtolower($string);

Returns string with all characters converted to lower case.

strtoupper

$uc_string = strtoupper($string);

Returns string with all characters converted to upper case.

strval

$string = strval($variable);

Returns variable as a string value.

substr

$substring = substr($string, $start, $length);

Returns the portion of string that begins at character start (0 is the first character) and continues for length characters.

symlink

symlink($target, $filename);

Creates a symbolic link from filename to target.

syslog

syslog($level, $message);

Logs message to the system logs at the level level.

system

$results = system($command);
$results = system($command, $return_value);

Executes the external command command and returns all output. If a second argument is provided, the return value of the command is placed there.

tan

$value = tan($number);

Returns the tangent of number (in radians).

tempnam

$filename = tempnam($path, $prefix);

Returns a filename, prepended with prefix, that will be unique in the directory specified by path.

time

$time = time();

Returns the current time in Unix standard time format (the number of seconds since Jan 1, 1970).

umask

$umask = umask();
umask($umask);

Returns the current umask if no argument is specified. Sets the umask to umask (which must be an octal number) if an argument is present.

uniqid

$result = uniqid();

Returns a value that is guaranteed to be unique compared to other values returned by repeated calls.

unlink

unlink($filename);

Deletes the specified file.

unset

unset($variable);

Undefines the specified variable, which may be an element of an array. When performed on an array, it erases the entire array.

urldecode

$decoded_string = urldecode($string);

Returns a copy of string that has all URL escape codes translated into their values. This is done automatically with all incoming form data.

urlencode

$encoded_string = urlencode($string);

Returns a copy of string that has all special characters URL encoded.

usleep

usleep($ms);

Stops the parsing of the script for ms microseconds.

virtual

virtual($filename);

Includes filename exactly as if the tag <!--#include virtual="$filename" --> were present in a standard HTML file. This function is useful only in conjunction with the Apache web server.



Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.