files-shared-code-tce-functions-general

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.

tce_functions_general.php

Tags
file

General functions.

author

Nicola Asuni

since
2001-09-08

Table of Contents

Functions

F_count_rows()  : number
Count rows of the given table.
F_empty_to_null()  : string
Prepare field value for SQL query.<br> Returns the quoted string if not empty, NULL otherwise.
F_zero_to_null()  : string
Prepare field value for SQL query.<br> Returns the num if different from zero, NULL otherwise.
F_getBoolean()  : bool
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.
F_check_unique()  : bool
Check if specified fields are unique on table.
unhtmlentities()  : converted
Reverse function for htmlentities.
F_compact_string()  : converted
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>
F_replace_angulars()  : converted
Replace angular parenthesis with html equivalents (html entities).
F_substr_utf8()  : substring
Performs a multi-byte safe substr() operation based on number of characters.
F_text_to_xml()  : converted
Escape some special characters (&lt; &gt; &amp;).
F_xml_to_text()  : converted
Unescape some special characters (&lt; &gt; &amp;).
F_text_to_tsv()  : converted
Escape some special characters for TSV output.
F_tsv_to_text()  : converted
Unescape some special characters from TSV format.
showRequiredField()  : html
Return a string containing an HTML acronym for required/not required fields.
utrim()  : string
Strip whitespace (or other characters) from the beginning and end of an UTF-8 string and replace the "\xA0" with normal space.
getNormalizedIP()  : string
Convert all IP addresses to IPv6 expanded notation.
getIpAsInt()  : int
Converts a string containing an IP address into its integer value.
getIpAsString()  : int
Converts a string containing an IP address into its integer value and return string representation.
F_formatFloat()  : formatted
Format a percentage number.
F_formatPercentage()  : formatted
Format a percentage number.
F_formatPdfPercentage()  : string
format a percentage number
F_formatXMLPercentage()  : string
format a percentage number for XML
F_getUTCoffset()  : int
Returns the UTC time offset in seconds
F_db_getUTCoffset()  : string
Returns the UTC time offset yo be used with CONVERT_TZ function
getDataXML()  : string
Get data array in XML format.
getDataTSVHeader()  : string
Get data headers (keys) in TSV header (tab separated text values).
getDataTSV()  : string
Get data in TSV format (tab separated text values).
F_html_to_TSV()  : string
Convert HTML code to TSV string.
F_select_table_header_element()  : table
Display table header element with order link.
getContrastColor()  : string
Get a black or white color that maximize contrast.
F_isURL()  : bool
Returns true if the string is an URL.
F_utf8_normalizer()  : normalized
Normalize the UTF-8 input string.
bcdechex()  : string
Convert an long integer number to a Hexadecimal representation

Functions

F_count_rows()

Count rows of the given table.

F_count_rows( $dbtable[,  $where = '' ]) : number
Parameters
$dbtable :

(string) database table name

$where : = ''

(string) optional where SQL clause (including the WHERE keyword).

Return values
number

of rows

F_empty_to_null()

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

F_empty_to_null( $str) : string
Parameters
$str :

(string) string to check.

Return values
string

$str quoted if not empty, NULL otherwise

F_zero_to_null()

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

F_zero_to_null( $num) : string
Parameters
$num :

(string) string to check.

Return values
string

$num if != 0, NULL otherwise

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.

F_getBoolean( $str) : bool
Parameters
$str :

(string) string to check.

Return values
bool

value.

F_check_unique()

Check if specified fields are unique on table.

F_check_unique( $table,  $where[,  $fieldname = false ][,  $fieldid = false ]) : bool
Parameters
$table :

(string) table name

$where :

(string) SQL where clause

$fieldname : = false

(mixed) name of table column to check

$fieldid : = false

(mixed) ID of table row to check

Return values
bool

true if unique, false otherwise

unhtmlentities()

Reverse function for htmlentities.

unhtmlentities( $text_to_convert[,  $preserve_tagsign = false ]) : converted
Parameters
$text_to_convert :

(string) input string to convert

$preserve_tagsign : = false

(boolean) if true preserve <> symbols, default=FALSE

Return values
converted

string

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>

F_compact_string( $string[,  $dquotes = false ]) : converted
Parameters
$string :

(string) input string to convert

$dquotes : = false

(boolean) If true add slash in fron of double quotes;

Return values
converted

string

F_replace_angulars()

Replace angular parenthesis with html equivalents (html entities).

F_replace_angulars( $str) : converted
Parameters
$str :

(string) input string to convert

Return values
converted

string

F_substr_utf8()

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

F_substr_utf8( $str,  $start,  $length) : substring
Parameters
$str :

(string) input string

$start :

(int) substring start index

$length :

(int) substring max lenght

Return values
substring

F_text_to_xml()

Escape some special characters (&lt; &gt; &amp;).

F_text_to_xml( $str) : converted
Parameters
$str :

(string) input string to convert

Return values
converted

string

F_xml_to_text()

Unescape some special characters (&lt; &gt; &amp;).

F_xml_to_text( $str) : converted
Parameters
$str :

(string) input string to convert

Return values
converted

string

F_text_to_tsv()

Escape some special characters for TSV output.

F_text_to_tsv( $str) : converted
Parameters
$str :

(string) input string to convert

Return values
converted

string

F_tsv_to_text()

Unescape some special characters from TSV format.

F_tsv_to_text( $str) : converted
Parameters
$str :

(string) input string to convert

Return values
converted

string

showRequiredField()

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

showRequiredField([ $mode = 1 ]) : html
Parameters
$mode : = 1

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

Return values
html

string

utrim()

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

utrim( $txt) : string
Parameters
$txt :

(string) The string that will be trimmed.

Return values
string

The trimmed string.

getNormalizedIP()

Convert all IP addresses to IPv6 expanded notation.

getNormalizedIP( $ip) : string
Parameters
$ip :

(string) IP address to normalize.

Tags
since
7.1.000

(2009-02-13)

Return values
string

IPv6 address in expanded notation or false in case of invalid input.

getIpAsInt()

Converts a string containing an IP address into its integer value.

getIpAsInt( $ip) : int
Parameters
$ip :

(string) IP address to convert.

Tags
since
7.1.000

(2009-02-13)

Return values
int

IP address as integer number.

getIpAsString()

Converts a string containing an IP address into its integer value and return string representation.

getIpAsString( $ip) : int
Parameters
$ip :

(string) IP address to convert.

Tags
since
9.0.033

(2009-11-03)

Return values
int

IP address as string.

F_formatFloat()

Format a percentage number.

F_formatFloat( $num) : formatted
Parameters
$num :

(float) number to be formatted

Return values
formatted

string

F_formatPercentage()

Format a percentage number.

F_formatPercentage( $num[,  $ratio = true ]) : formatted
Parameters
$num :

(float) Number to be formatted.

$ratio : = true

(boolean) Set to true if the number is a ratio between 0 and 1, false if is a percentage number between 0 an 100.

Return values
formatted

string

F_formatPdfPercentage()

format a percentage number

F_formatPdfPercentage( $num[,  $ratio = true ]) : string
Parameters
$num :

(float) number to be formatted

$ratio : = true

(boolean) Set to true if the number is a ratio between 0 and 1, false if is a percentage number between 0 an 100.

Return values
string

F_formatXMLPercentage()

format a percentage number for XML

F_formatXMLPercentage( $num[,  $ratio = true ]) : string
Parameters
$num :

(float) number to be formatted

$ratio : = true

(boolean) Set to true if the number is a ratio between 0 and 1, false if is a percentage number between 0 an 100.

Return values
string

F_getUTCoffset()

Returns the UTC time offset in seconds

F_getUTCoffset( $timezone) : int
Parameters
$timezone :

(string) current user timezone

Return values
int

UTC time offset in seconds

F_db_getUTCoffset()

Returns the UTC time offset yo be used with CONVERT_TZ function

F_db_getUTCoffset( $timezone) : string
Parameters
$timezone :

(string) current user timezone

Return values
string

UTC time offset (+HH:mm)

getDataXML()

Get data array in XML format.

getDataXML( $data[,  $level = 1 ]) : string
Parameters
$data :

(array) Array of data (key => value).

$level : = 1

(int) Indentation level.

Return values
string

XML data

getDataTSVHeader()

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

getDataTSVHeader( $data[,  $prefix = '' ]) : string
Parameters
$data :

(array) Array of data (key => value).

$prefix : = ''

(string) Prefix to add to keys.

Return values
string

data

getDataTSV()

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

getDataTSV( $data) : string
Parameters
$data :

(array) Array of data.

Return values
string

XML data

F_html_to_TSV()

Convert HTML code to TSV string.

F_html_to_TSV( $str) : string
Parameters
$str :

(string) HTML string to convert.

Return values
string

TSV

F_select_table_header_element()

Display table header element with order link.

F_select_table_header_element( $order_field,  $orderdir,  $title,  $name[,  $current_order_field = '' ][,  $filter = '' ]) : table
Parameters
$order_field :

(string) name of table field

$orderdir :

(string) order direction

$title :

title (string) field of anchor link

$name :

column (string) name

$current_order_field : = ''

(string) current order field name

$filter : = ''

(string) additional parameters to pass on URL

Return values
table

header element string

getContrastColor()

Get a black or white color that maximize contrast.

getContrastColor( $color) : string
Parameters
$color :

(string) color in HEX format.

Return values
string

Color.

F_isURL()

Returns true if the string is an URL.

F_isURL( $str) : bool
Parameters
$str :

(string) String to check.

Return values
bool

true or false.

F_utf8_normalizer()

Normalize the UTF-8 input string.

F_utf8_normalizer( $str[,  $mode = 'NONE' ]) : normalized

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

Parameters
$str :

(string) UTF-8 string to normalize.

$mode : = 'NONE'

(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'.

Return values
normalized

string using the specified algorithm.

bcdechex()

Convert an long integer number to a Hexadecimal representation

bcdechex(string|int $dec) : string
Parameters
$dec : string|int

Decimal number to convert.

Tags
author

Nicola Asuni

since
2013-07-02
Return values
string

containing the HEX representation in uppercase.

On this page
 

© 2004-2024 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy