Built-in Functions
Mathematical Functions
ceil(fraction) - rounds a fraction up to the next higher integer.
floor(fraction) - rounds a fraction down to the next lowest integer.
number_format("number", "decimals", "decimal point", "thousands_sep") - returns formatted version of a specified number.
pow(number, exponent) - returns the value of a given number, raised to the power of a given exponent.
rand(min, max) - generates a random value from a specific range of numbers.
round(fraction) - rounds a fraction up to the next higher or next lower integer.
sqrt(number) - returns the square root of a given number.
String Functions
strlen(string) - determines the length of a string.
ltrim(string) - strips whitespace from the beginning of a string.
rtrim(string) - strips whitespace from the end of a string.
strpbrk(string, char) - Searchs the string for the character (char). Returns false or string beginning with the
character found.
strtoupper(string) - converts string to uppercase.
strtolower(string) - converts string to lowercase.
strrev(string) - reverses a string.
eregi(string pattern, string subject) - Performs a case insensitive expression match.
Searches subject for a match to the regular expression given in pattern.
Error Functions
exit("message") - displays error message and terminates current script.
die("message") - displays error message and terminates current script.
Email Function
mail("recipient","subject", "message", "mail headers") - sends mail to a specified recipient.
HTTP/Session Functions
header()- outputs an HTTP header string, such as location redirection.
setcookie("name", "value", "expire", "path", "domain", "secure") - sends a cookie to the user.
session_start("name", "value", "expire", "path", "domain", "secure") - sends a cookie to the user.
setcookie("name", "value", "expire", "path", "domain", "secure") - sends a cookie to the user.
session_start() - - initializes session data. This function is called prior to creating a new session variable using $_SESSION.
session_destroy() - destroys all data registered to a script's current session
File Functions
fopen(filename, mode)- function used to open a file. The function requires a filename and mode. It returns a file
pointer which provides information about the file and is used as a reference.
fread(resource handle, length) - function used to read the contents of a file.
Reads up to length bytes from the file pointer referenced by handle. Reading stops
when length bytes have been read, EOF (end of file) is reached. The function requires
two parameters - a file pointer that is created when the file is opened with fopen()
and a filesize that specifies how much of the file contents to read.
fgetcsv(resource handle, length, delimiter) - function used to read the contents of a file and parses the data to create an array. Data is parsed on the delimiter parameter supplied to the function.
filesize(filename) - returns the size of a file. If an error occurs the function returns a false value.
fclose(resource handle) - function used to close a file. The function requires the file pointer created when the file
was opened using the fopen() function. Returns TRUE on success or FALSE on failure.
fwrite(resource handle,string) - writes the contents of string to the file stream pointed to by handle. If the length argument is given, writing will stop
after length bytes have been written or the end of string is reached, whichever comes first.
copy(original filename, new filename) - copies the contents of an original file defined by the first parameter to a new file defined by the second function parameter. The function returns a true or false value.
unlink(filename) - deletes the file defined by the first parameter. The function returns a true or false value.
rename($orig_filename, $new_filename) - renames the file defined by the first parameter to the name defined as the second parameter. The function returns a true or false value.
ODBC Functions
odbc_connect(dsn/dsn-less connection string,username,password) -
function used to connect to
an ODBC datasource. The function takes four parameters: the data source name or a dsn-less connection
string, username,
password, and an optional cursor type. In cases where a username and password, and
cursor type are not required, the parameters can be replaced with a null
string - ''. The connection id returned by this functions is needed by other
ODBC functions. You can have multiple connections open at once as long as they either use
different db or different credentials.
odbc_exec(connection_id,SQL query_string) - function used to execute an SQL statement.
The function takes two parameters: a connection object created using the odbc_connect() function and a SQL
statement. Returns FALSE on error. Returns a record set if the SQL command
was executed successfully.
odbc_fetch_array(recordset name) - used to retrieve records or rows from a record set as an associative array. The recordset name is created when the odbc_exec() function is called. This function returns TRUE
if it is able to return rows, otherwise FALSE.
odbc_num_rows(recordset name) - returns the number of rows in an ODBC result set. The function will return -1 if an error occurs. For INSERT, UPDATE and DELETE statements odbc_num_rows() returns the number of rows affected. For a SELECT clause this can be the number of rows available. Note: Using odbc_num_rows() to determine the number of rows available after a SELECT will return -1 with MS Access drivers.
odbc_close(connection_id) - will close down the connection to the database server associated
with the given connection identifier.
MySQL Functions
mysql_connect(MySQL server name,username,password) - opens a connection to a MySQL server.
mysql_select_db(database name,connection identifier) - selects a database residing on the MySQL server. The
database name parameter referes to an active database on the MySQL server that was opened with the mysql_connect
function. The connection identifier is a reference to the current MySQL connection.
mysql_query(sql query) - sends a query to the currently active database.
mysql_fetch_array(resourse result) - Returns an array that corresponds to the fetched row and moves the
internal data pointer ahead.
mysql_affected_rows(resourse result) - determines the number of rows affected by the previous SQL operation.
mysql_close(link_identifier) - closes MySQL connection.