File/engine/utility.php

Description

Utility functions

This module contains several wide-purpose utility functions.

Includes
 require_once ('../engine/smtp.php') (line 83)

Dependency.

 require_once ('../engine/debug.php') (line 82)

Dependency.

Constants
CSV_DELIMITERS = '!#$%&\'()*+,-./:;<=>?@[\]^_`{|}~' (line 105)

Allowed CSV-delimiters.

MAXINT = 0x7FFFFFFF (line 93)

Maximum integer value.

SECS_IN_DAY = 86400 (line 98)

Number of seconds.

SECS_IN_WEEK = 604800 (line 99)

Number of seconds.

Functions
bool2sql (line 424)

Converts boolean value to integer for use in SQL queries.

  • return: '1' on TRUE, or '0' on FALSE.
int bool2sql (bool $value)
  • bool $value: Boolean value.
date_floor (line 591)

Round specified timestamp down to midnight.

int date_floor (int $timestamp)
date_offset (line 605)

Returns timestamp, shifted from specified for particular number of days.

Negative offset shifts to past, positive - to future.

int date_offset (int $timestamp, int $offset)
get_http_auth_realm (line 636)

Generates Basic HTTP Authentication realm, based on client browser.

  • return: Generated realm.
string get_http_auth_realm ()
is_email (line 486)

Finds whether the given UTF-8 encoded string contains valid email address.

  • return: TRUE if str contains valid email address, FALSE otherwise.
bool is_email (string $str)
  • string $str: The UTF-8 encoded string being evaluated.
is_intvalue (line 461)

Finds whether the given UTF-8 encoded string contains valid integer value.

  • return: TRUE if str contains valid integer value, FALSE otherwise.
bool is_intvalue (string $str)
  • string $str: The UTF-8 encoded string being evaluated.
is_username (line 474)

Finds whether the given UTF-8 encoded string contains valid login (only latin characters, digits, and underline are allowed).

  • return: TRUE if str contains valid login, FALSE otherwise.
bool is_username (string $str)
  • string $str: The UTF-8 encoded string being evaluated.
sendmail (line 510)

Sends email notification.

  • return: TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
bool sendmail (string $sender, string $from, string $to, string $subject, string $message, [int $attachment_id = NULL], [string $attachment_name = NULL], [string $attachment_type = NULL], [int $attachment_size = NULL])
  • string $sender: Name of sender.
  • string $from: Email address of sender.
  • string $to: Email addresses of recipients (comma-separated).
  • string $subject: Subject of the notification.
  • string $message: Body of the notification.
  • int $attachment_id: ID of attachment if it should be included in email, NULL otherwise.
  • string $attachment_name: Name of attachment if it should be included in email, NULL otherwise.
  • string $attachment_type: MIME type of attachment if it should be included in email, NULL otherwise.
  • int $attachment_size: Size of attachment if it should be included in email, NULL otherwise.
swap (line 448)

Exchanges values of two variables.

void swap (mixed &$value1, mixed &$value2)
  • mixed &$value1: First variable.
  • mixed &$value2: Second variable.
time2ustr (line 317)

Converts specified amount of minutes to its string representation in format "hh:mm".

  • return: String representation (e.g. for 127 it will be "2:07").
string time2ustr (int $time)
  • int $time: Amount of minutes.
try_request (line 436)

Returns value of user HTML-form request, if it exists; otherwise returns specified default value.

  • return: User HTML-form request, or default value if specified request cannot be found.
mixed try_request (string $request, [mixed $value = NULL])
  • string $request: Name of user HTML-form request.
  • mixed $value: Default value.
ustr2csv (line 374)

Convert UTF-8 encoded string to CSV format.

  • return: CSV string (UTF-8 encoded).
string ustr2csv (string $str, [string $delimiter = ','], [string $enclosure = '&quot;'])
  • string $str: The UTF-8 encoded string.
  • string $delimiter: CSV delimiter.
  • string $enclosure: CSV enclosure.
ustr2html (line 328)

Strips HTML-tags from UTF-8 encoded string.

  • return: HTML-safe UTF-8 encoded string.
string ustr2html (string $str)
  • string $str: The UTF-8 encoded string.
ustr2int (line 295)

Converts UTF-8 encoded string to integer (natural) value.

If resulted integer value is less then specified min value, the min value will be returned. If resulted integer value is greater then specified max value, the max value will be returned.

  • return: Natural value of range from min to max.
int ustr2int (string $str, [int $min = 0], [int $max = MAXINT])
  • string $str: The UTF-8 encoded string being converted.
  • int $min: Minimum allowed result value.
  • int $max: Maximum allowed result value.
ustr2js (line 342)

Strips quotes from UTF-8 encoded string.

  • return: JavaScript-safe UTF-8 encoded string.
string ustr2js (string $str)
  • string $str: The UTF-8 encoded string.
ustr2sql (line 353)

Strips apostrophes from UTF-8 encoded string.

  • return: SQL-safe UTF-8 encoded string.
string ustr2sql (string $str)
  • string $str: The UTF-8 encoded string.
ustrcut (line 244)

Trims UTF-8 encoded string and then cuts it to specified length.

  • return: Cut string.
string ustrcut (string $str, int $maxlen)
  • string $str: The UTF-8 encoded string being cut.
  • int $maxlen: New length of the string (amount of UTF-8 characters).
ustripos (line 153)

Unicode (UTF-8) analogue of standard stripos PHP function.

Find position of first occurrence of a case-insensitive UTF-8 encoded string. Returns the numeric position (offset in amount of UTF-8 characters) of the first occurrence of needle in the haystack string.

  • return: Returns the position as an integer. If needle is not found, the function will return boolean FALSE.
int ustripos (string $haystack, string $needle, [int $offset = 0])
  • string $haystack: The UTF-8 encoded string being searched in.
  • string $needle: The UTF-8 encoded string being searched for.
  • int $offset: The optional offset parameter allows you to specify which character in haystack to start searching. The position returned is still relative to the beginning of haystack.
ustrlen (line 119)

Unicode (UTF-8) analogue of standard strlen PHP function.

Returns the length of the given string.

  • return: The length (amount of UTF-8 characters) of the string on success, and 0 if the string is empty.
int ustrlen (string $str)
  • string $str: The UTF-8 encoded string being measured for length.
ustrpos (line 136)

Unicode (UTF-8) analogue of standard strpos PHP function.

Find position of first occurrence of a case-sensitive UTF-8 encoded string. Returns the numeric position (offset in amount of UTF-8 characters) of the first occurrence of needle in the haystack string.

  • return: Returns the position as an integer. If needle is not found, the function will return boolean FALSE.
int ustrpos (string $haystack, string $needle, [int $offset = 0])
  • string $haystack: The UTF-8 encoded string being searched in.
  • string $needle: The UTF-8 encoded string being searched for.
  • int $offset: The optional offset parameter allows you to specify which character in haystack to start searching. The position returned is still relative to the beginning of haystack.
ustrprocess (line 272)

The function accepts variable number of arguments and replaces each "%i" (where i is a natural number) substring of input string with related argument.

Passed arguments can be any type of; in case of string they should be UTF-8 encoded.

  • return:

    Processed string.


    Example:

    1.  ustrprocess("Name: %1\nSex: %3\nAge: %2""Artem"30"male");

    will output
     Name: Artem
     Sex: male
     Age: 30

string ustrprocess (string $str, mixed 1, mixed 2, mixed 3)
  • string $str: The UTF-8 encoded string being processed.
  • mixed 1: Value, which each "%1" substring will be replaced with.
  • mixed 2: Value, which each "%2" substring will be replaced with.
  • mixed 3: ... (and so on)
ustrrpos (line 171)

Unicode (UTF-8) analogue of standard strrpos PHP function.

Find position of last occurrence of a case-sensitive UTF-8 encoded string. Returns the numeric position (offset in amount of UTF-8 characters) of the last occurrence of needle in the haystack string.

  • return: Returns the position as an integer. If needle is not found, the function will return boolean FALSE.
int ustrrpos (string $haystack, string $needle)
  • string $haystack: The UTF-8 encoded string being searched in.
  • string $needle: The UTF-8 encoded string being searched for.
ustrtolower (line 184)

Unicode (UTF-8) analogue of standard strtolower PHP function.

Make a string lowercase.

  • return: Specified string with all alphabetic characters converted to lowercase.
string ustrtolower (string $str)
  • string $str: The UTF-8 encoded string to be lowercased.
ustr_getcsv (line 396)

Parse UTF-8 encoded CSV string into an array.

  • return: Indexed array containing the fields read (UTF-8 encoded), or NULL on error.
array ustr_getcsv (string $str, [string $delimiter = ','], [string $enclosure = '&quot;'])
  • string $str: The UTF-8 encoded CSV string.
  • string $delimiter: CSV delimiter.
  • string $enclosure: CSV enclosure.
ustr_replace (line 216)

Unicode (UTF-8) analogue of standard str_replace PHP function.

Replace all occurrences of the search string with the replacement string.

  • return: The UTF-8 encoded string with the replaced values.
string ustr_replace (string $search, string $replace, string $subject)
  • string $search: The UTF-8 encoded string being searched for.
  • string $replace: The UTF-8 encoded string being replaced with.
  • string $subject: The UTF-8 encoded string being searched in.
usubstr (line 201)

Unicode (UTF-8) analogue of standard substr PHP function.

Returns the portion of string specified by the start and length parameters.

  • return: The extracted UTF-8 encoded part of input string.
string usubstr (string $str, int $start, [int $length = NULL])
  • string $str: The UTF-8 encoded string.
  • int $start: Start of portion to be returned. Position is counted in amount of UTF-8 characters from the beginning of str. First character's position is 0. Second character position is 1, and so on.
  • int $length: If length is given, the string returned will contain at most length characters beginning from start (depending on the length of string). If length is omitted, the rest of string from start will be returned.

Documentation generated on Tue, 17 Nov 2009 12:33:00 +1000 by phpDocumentor 1.4.3