tce_functions_general.php

General functions.

Source: shared/code/tce_functions_general.php

General functions.

Functions

bcdechex()

Convert an long integer number to a Hexadecimal representation

function bcdechex(string|int $dec): string

Parameters:

  • $dec (string|int): Decimal number to convert.

Returns: string: containing the HEX representation in uppercase.

Source: shared/code/tce_functions_general.php:803

F_check_unique()

Check if specified fields are unique on table.

function F_check_unique(
    mixed $table,
    mixed $where,
    mixed $fieldname = false,
    mixed $fieldid = false
): bool

Parameters:

  • $table (mixed): (string) table name
  • $where (mixed): (string) SQL where clause
  • $fieldname (mixed): (mixed) name of table column to check
  • $fieldid (mixed): (mixed) ID of table row to check

Returns: bool: true if unique, false otherwise

Source: shared/code/tce_functions_general.php:107

F_compact_string()

Remove the following characters: <ul> <li>"\t" (ASCII 9 (0x09)), a tab.</li> <li>"\n" (ASCII 10 (0x0A)), a new line (line feed)</li> <li>"\r" (ASCII 13 (0x0D)), a carriage return</li> <li>"\0" (ASCII 0 (0x00)), the NUL-byte</li> <li>"\x0B" (ASCII 11 (0x0B)), a vertical tab</li> </ul>

function F_compact_string(mixed $string, mixed $dquotes = false): converted

Parameters:

  • $string (mixed): (string) input string to convert
  • $dquotes (mixed): (boolean) If true add slash in fron of double quotes;

Returns: converted: string

Source: shared/code/tce_functions_general.php:161

F_count_rows()

Count rows of the given table.

function F_count_rows(mixed $dbtable, mixed $where = ''): number

Parameters:

  • $dbtable (mixed): (string) database table name
  • $where (mixed): (string) optional where SQL clause (including the WHERE keyword).

Returns: number: of rows

Source: shared/code/tce_functions_general.php:29

F_db_getUTCoffset()

Returns the UTC time offset yo be used with CONVERT_TZ function

function F_db_getUTCoffset(mixed $timezone): string

Parameters:

  • $timezone (mixed): (string) current user timezone

Returns: string: UTC time offset (+HH:mm)

Source: shared/code/tce_functions_general.php:542

F_empty_to_null()

Prepare field value for SQL query.<br> Returns the quoted string if not empty, NULL otherwise.

function F_empty_to_null(mixed $str): string

Parameters:

  • $str (mixed): (string) string to check.

Returns: string: $str quoted if not empty, NULL otherwise

Source: shared/code/tce_functions_general.php:52

F_formatFloat()

Format a percentage number.

function F_formatFloat(mixed $num): formatted

Parameters:

  • $num (mixed): (float) number to be formatted

Returns: formatted: string

Source: shared/code/tce_functions_general.php:475

F_formatPdfPercentage()

format a percentage number

function F_formatPdfPercentage(mixed $num, mixed $ratio = true): string

Parameters:

  • $num (mixed): (float) number to be formatted
  • $ratio (mixed): (boolean) Set to true if the number is a ratio between 0 and 1, false if is a percentage number between 0 an 100.

Returns: string

Source: shared/code/tce_functions_general.php:501

F_formatPercentage()

Format a percentage number.

function F_formatPercentage(mixed $num, mixed $ratio = true): formatted

Parameters:

  • $num (mixed): (float) Number to be formatted.
  • $ratio (mixed): (boolean) Set to true if the number is a ratio between 0 and 1, false if is a percentage number between 0 an 100.

Returns: formatted: string

Source: shared/code/tce_functions_general.php:486

F_formatXMLPercentage()

format a percentage number for XML

function F_formatXMLPercentage(mixed $num, mixed $ratio = true): string

Parameters:

  • $num (mixed): (float) number to be formatted
  • $ratio (mixed): (boolean) Set to true if the number is a ratio between 0 and 1, false if is a percentage number between 0 an 100.

Returns: string

Source: shared/code/tce_functions_general.php:516

F_getBoolean()

Returns boolean value from string or integer.<br> This function is needed to get the right boolean value from boolean field returned by PostgreSQL query.

function F_getBoolean(mixed $str): bool

Parameters:

  • $str (mixed): (string) string to check.

Returns: bool: value.

Source: shared/code/tce_functions_general.php:86

F_getUTCoffset()

Returns the UTC time offset in seconds

function F_getUTCoffset(mixed $timezone): int

Parameters:

  • $timezone (mixed): (string) current user timezone

Returns: int: UTC time offset in seconds

Source: shared/code/tce_functions_general.php:530

F_html_to_TSV()

Convert HTML code to TSV string.

function F_html_to_TSV(mixed $str): string

Parameters:

  • $str (mixed): (string) HTML string to convert.

Returns: string: TSV

Source: shared/code/tce_functions_general.php:623

F_isURL()

Returns true if the string is an URL.

function F_isURL(mixed $str): bool

Parameters:

  • $str (mixed): (string) String to check.

Returns: bool: true or false.

Source: shared/code/tce_functions_general.php:737

F_replace_angulars()

Replace angular parenthesis with html equivalents (html entities).

function F_replace_angulars(mixed $str): converted

Parameters:

  • $str (mixed): (string) input string to convert

Returns: converted: string

Source: shared/code/tce_functions_general.php:182

F_select_table_header_element()

Display table header element with order link.

function F_select_table_header_element(
    mixed $order_field,
    mixed $orderdir,
    mixed $title,
    mixed $name,
    mixed $current_order_field = '',
    mixed $filter = ''
): table

Parameters:

  • $order_field (mixed): (string) name of table field
  • $orderdir (mixed): (string) order direction
  • $title (mixed): title (string) field of anchor link
  • $name (mixed): column (string) name
  • $current_order_field (mixed): (string) current order field name
  • $filter (mixed): (string) additional parameters to pass on URL

Returns: table: header element string

Source: shared/code/tce_functions_general.php:678

F_substr_utf8()

Performs a multi-byte safe substr() operation based on number of characters.

function F_substr_utf8(mixed $str, mixed $start, mixed $length): substring

Parameters:

  • $str (mixed): (string) input string
  • $start (mixed): (int) substring start index
  • $length (mixed): (int) substring max length

Returns: substring

Source: shared/code/tce_functions_general.php:198

F_text_to_tsv()

Escape some special characters for TSV output.

function F_text_to_tsv(mixed $str): converted

Parameters:

  • $str (mixed): (string) input string to convert

Returns: converted: string

Source: shared/code/tce_functions_general.php:277

F_text_to_xml()

Escape some special characters (< > &).

function F_text_to_xml(mixed $str): converted

Parameters:

  • $str (mixed): (string) input string to convert

Returns: converted: string

Source: shared/code/tce_functions_general.php:238

F_tsv_to_text()

Unescape some special characters from TSV format.

function F_tsv_to_text(mixed $str): converted

Parameters:

  • $str (mixed): (string) input string to convert

Returns: converted: string

Source: shared/code/tce_functions_general.php:297

F_utf8_normalizer()

Normalize the UTF-8 input string.

Modes greater than 0 requires php5-intl module. Please edit this function to implement your custom normalization method.

function F_utf8_normalizer(mixed $str, mixed $mode = 'NONE'): normalized

Parameters:

  • $str (mixed): (string) UTF-8 string to normalize.
  • $mode (mixed): (int) Normalization type: NONE=None; C=Normalization Form C (NFC) - Canonical Decomposition followed by Canonical Composition; D=Normalization Form D (NFD) - Canonical Decomposition; KC=Normalization Form KC (NFKC) - Compatibility Decomposition, followed by Canonical Composition; KD=Normalization Form KD (NFKD) - Compatibility Decomposition; CUSTOM=Custom normalization using user defined function ‘user_utf8_custom_normalizer’.

Returns: normalized: string using the specified algorithm.

Source: shared/code/tce_functions_general.php:750

F_xml_to_text()

Unescape some special characters (< > &).

function F_xml_to_text(mixed $str): converted

Parameters:

  • $str (mixed): (string) input string to convert

Returns: converted: string

Source: shared/code/tce_functions_general.php:258

F_zero_to_null()

Prepare field value for SQL query.<br> Returns the num if different from zero, NULL otherwise.

function F_zero_to_null(mixed $num): string

Parameters:

  • $num (mixed): (string) string to check.

Returns: string: $num if != 0, NULL otherwise

Source: shared/code/tce_functions_general.php:69

getContrastColor()

Get a black or white color that maximize contrast.

function getContrastColor(mixed $color): string

Parameters:

  • $color (mixed): (string) color in HEX format.

Returns: string: Color.

Source: shared/code/tce_functions_general.php:716

getDataTSV()

Get data in TSV format (tab separated text values).

function getDataTSV(mixed $data): string

Parameters:

  • $data (mixed): (array) Array of data.

Returns: string: XML data

Source: shared/code/tce_functions_general.php:604

getDataTSVHeader()

Get data headers (keys) in TSV header (tab separated text values).

function getDataTSVHeader(mixed $data, mixed $prefix = ''): string

Parameters:

  • $data (mixed): (array) Array of data (key => value).
  • $prefix (mixed): (string) Prefix to add to keys.

Returns: string: data

Source: shared/code/tce_functions_general.php:585

getDataXML()

Get data array in XML format.

function getDataXML(mixed $data, mixed $level = 1): string

Parameters:

  • $data (mixed): (array) Array of data (key => value).
  • $level (mixed): (int) Indentation level.

Returns: string: XML data

Source: shared/code/tce_functions_general.php:555

getIpAsBytes()

Converts an IP address into its packed 16-byte binary representation (network byte order).

This preserves full 128-bit precision and is case-insensitive, so the returned fixed-width byte strings can be ordered and range-compared losslessly with strcmp() (see F_isValidIP). Input may use any notation accepted by getNormalizedIP() (IPv4, IPv6, or the expanded form already stored in the database).

function getIpAsBytes(mixed $ip): string|false

Parameters:

  • $ip (mixed): (string) IP address to convert.

Returns: string|false: 16-byte packed IPv6 address, or false on invalid input.

Source: shared/code/tce_functions_general.php:426

getIpAsString()

Returns a human-readable, compact string representation of an IP address.

The stored form is the expanded IPv6 produced by getNormalizedIP(); this compacts it (and unwraps IPv4-mapped IPv6, e.g. ::ffff:127.0.0.1 -> 127.0.0.1) so it reads naturally and fits report/result columns.

function getIpAsString(mixed $ip): string

Parameters:

  • $ip (mixed): (string) IP address to convert.

Returns: string: IP address as a readable string.

Source: shared/code/tce_functions_general.php:445

getNormalizedIP()

Convert all IP addresses to IPv6 expanded notation.

function getNormalizedIP(mixed $ip): string|false

Parameters:

  • $ip (mixed): (string) IP address to normalize.

Returns: string|false: IPv6 address in expanded notation or false in case of invalid input.

Source: shared/code/tce_functions_general.php:349

showRequiredField()

Return a string containing an HTML abbreviation for required/not required fields.

function showRequiredField(mixed $mode = 1): html

Parameters:

  • $mode (mixed): (int) field mode: 1=not required; 2=required.

Returns: html: string

Source: shared/code/tce_functions_general.php:316

unhtmlentities()

Reverse function for htmlentities.

function unhtmlentities(mixed $text_to_convert, mixed $preserve_tagsign = false): converted

Parameters:

  • $text_to_convert (mixed): (string) input string to convert
  • $preserve_tagsign (mixed): (boolean) if true preserve <> symbols, default=FALSE

Returns: converted: string

Source: shared/code/tce_functions_general.php:139

utrim()

Strip whitespace (or other characters) from the beginning and end of an UTF-8 string and replace the “\xA0” with normal space.

function utrim(mixed $txt): string

Parameters:

  • $txt (mixed): (string) The string that will be trimmed.

Returns: string: The trimmed string.

Source: shared/code/tce_functions_general.php:332