/stdinc.php

Description

Library of commonly-used PHP functions.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Constants
STATE_MODE_GET = "GET" (line 36)

Maintain state with GET-mode formatting.

STATE_MODE_POST = "POST" (line 41)

Maintain state with POST-mode formatting.

Functions
day_number (line 114)

Returns the number of days since the epoch.

  • return: Day number of the date.
int day_number (int $_date)
  • int $_date: Unix timestamp of the date.
db_fetch_assoc (line 344)

Fetches a row from a given result set from the database. This is a wrapper for DB-specific methods, so you should be fairly easily able to change the specific database method called within here and make it work transparently.

  • return: Associative array that corresponds to the fetched row, or FALSE if there are no more rows.
array db_fetch_assoc (resource $_result)
  • resource $_result: Result set from which to fetch the row.
db_fetch_object (line 357)

Fetches an object from a given result set from the database, as an object of the type specified by $_className. This class definition must be already defined.

  • return: containing values fetched, of type $_class_name.
object Object db_fetch_object (resource $_result, string $_class_name)
  • resource $_result: Result set from which to fetch the row.
  • string $_class_name: Class name for the object to create.
db_fetch_row (line 330)

Fetches a row from a given result set from the database. This is a wrapper for DB-specific methods, so you should be fairly easily able to change the specific database method called within here and make it work transparently.

  • return: Array that corresponds to the fetched row, or FALSE if there are no more rows.
array db_fetch_row (resource $_result)
  • resource $_result: Result set from which to fetch the row.
db_insert_id (line 316)

Returns the last inserted ID from the database. This is a wrapper for DB-specific methods, so you should be fairly easily able to change the specific database method called within here and make it work transparently.

  • return: Last inserted ID from the database.
int db_insert_id ()
db_num_rows (line 379)

Fetches a row count from a given result set from the database. This is a wrapper for DB-specific methods, so you should be fairly easily able to change the specific database method called within here and make it work transparently.

  • return: Number of rows affected by query.
int db_num_rows (resource $_result)
  • resource $_result: Result set from which to fetch the row count.
db_query (line 302)

Performs a query on the database and returns the result set. This is a wrapper for DB-specific methods, so you should be fairly easily able to change the specific database method called within here and make it work transparently.

  • return: Result set arising from the query.
resource db_query (string $_query)
  • string $_query: SQL query to be performed.
getmicrotime (line 103)

Returns a float value of the current Unix timestamp with milliseconds, from the output of microtime().

  • return: Value of seconds plus millis.
float getmicrotime ()
html_select (line 201)

Displays a <select> box. Uses the normal conventions, e.g. table names begin with "tbl", key fields are "id" and identifier fields are "name".

void html_select (string $_name, string $_table, [int $_id = 0], [string $_where = ""], [string $_onChange = ""], [string $_style = ""], [string $_zeroText = ""], [string $_idField = "id"], [string $_nameField = "name"], [string $_orderBy = "name"], [string $_nameField2 = ""])
  • string $_name: Name of the HTML select box.
  • string $_table: Name of the table from which to get item data.
  • int $_id: ID of the item to be preselected.
  • string $_where: 'WHERE' clause to be used in the SQL query.
  • string $_onChange: JavaScript to execute on change.
  • string $_style: CSS attributes to apply.
  • string $_zeroText: Text value for the zero option.
  • string $_idField: Name of the field from which to get item IDs.
  • string $_nameField: Name of the field from which to get item names.
  • string $_orderBy: Name of the field by which to order items.
  • string $_nameField2: Name of the field for additional name data.
is_weekend (line 135)

Returns whether a date falls on a weekend.

boolean is_weekend (int $_date)
  • int $_date: Unix timestamp of the date.
lcfirst (line 65)

Makes a string's first character lowercase. Does the opposite of ucfirst.

  • return: String which has been converted.
string lcfirst (string $_str)
  • string $_str: String to be converted.
nice_date (line 146)

Returns a string representation of the date, of differing format depending on how recent the date is.

  • return: String representation of the date.
string nice_date (int $_date)
  • int $_date: Unix timestamp of the date.
nice_datetime (line 174)

Returns a string representation of the date and time, of differing format depending on how recent the date is.

  • return: String representation of the date and time.
string nice_datetime (int $_datetime)
  • int $_datetime: Unix timestamp of the date.
plural (line 76)

Returns the "s" character which appears on the end of plural numbers. Will return an empty string if no plural is required (i.e. the input was 1).

  • return: Either "s" or "" depending on whether $_int is 1.
string plural (int $_int)
  • int $_int: The integer which may or may not need pluralising.
redirect (line 279)

Sends HTTP headers to redirect elsewhere, then exits the script.

void redirect (string $_target)
  • string $_target: The URL to which the client should be redirected.
sp2nb (line 55)

Converts spaces to &nbsp; entities.

  • return: String which has been converted.
string sp2nb (string $_str)
  • string $_str: String to be converted.
state (line 249)

Maintains state.

To use, create a global array called $stateVars which contains strings representing the names of global variables you wish to pass around.

Example of using GET-mode syntax:

  1. print "example.php?".state( "GET" );

Example of using POST-mode syntax:

  1. print "<form action=\"example.php\" method=\"post\">";
  2. print state( "POST" );
  3. print "</form>";

  • return: String suitable for insertion into a URL (if $_mode is "GET"), or hidden input fields (if $_mode is "POST").
  • see: STATE_MODE_POST
  • see: STATE_MODE_GET
string state (string $_mode, [string $_omit = ""])
  • string $_mode: Either "GET" or "POST".
  • string $_omit: Comma-separated string of variables to omit.
weekday (line 125)

Returns the weekday of a date, according to date("w").

  • return: Weekday number of the date.
string weekday (int $_date)
  • int $_date: Unix timestamp of the date.
word_count (line 87)

Returns the number of words in a string. Words are counted in a fairly primitive but 'good enough' manner.

  • return: Number of words in the string.
int word_count (mixed $_str, string $str)
  • string $str: String to be counted.

Documentation generated on Mon, 11 Apr 2005 16:39:48 +0100 by phpDocumentor 1.3.0RC3