constructor
cphplib
cphplib
([
string $locale =
"de_DE"])
-
string
$locale: if no empty, locale and string will be initialised
computes the exact age (considering leap years!) of the person born on the specified birthday measured from today or a specified date
int
age_from_birthday
(string $date, [string $thisdate = ""], [char $date_format = "S"], [bool $fixed = false])
-
string
$date: Date on which the person was born
-
string
$thisdate: Date from which the age is measured (default: today)
-
char
$date_format: Format of the date and thisdate strings (default: "S"cience format)
-
bool
$fixed: if true, age of current year will be returned {default: false}
reverse sort array (subfunction for usort)
array
array_rsort
(array $a, array $b)
-
array
$a: keys
-
array
$b: values
sort array (subfunction for usort)
array
array_sort
(array $a, array $b)
-
array
$a: keys
-
array
$b: values
Removes duplicate values from an array (recursive) (this function is much slower than the internal php function)
array
array_unique
(array &$thearray)
-
array
$thearray: array to unique
Returns type of browser
char
browser_type
([bool $details = false])
-
bool
$details: true = return array with browser type and gecko engine version (only available for Mozilla based browsers) browser_type = browser type gecko_version = gecko version integer {default: 0} false = return letter for browser type {default: false}
validate German Bankleitzahl ( allowed seperators: "-", "." or " ")
bool
checkBankId
(string $bank_id)
-
string
$bank_id: bank id (German BLZ) to validate
Check birthday
bool
checkBirthday
(date $birthday, [char $date_format = "S"])
-
date
$birthday
-
char
$date_format
check if string is a valid color value for HTML and CSS
bool
checkColor
(string $str)
-
string
$str: string to validate
validate domain name
bool
checkDomainName
(string $domain, [string $tld = null])
-
string
$domain: domain name
-
string
$tld: top level domain
Verify EAN
bool
checkEAN
(string $ean, [string $type = null])
-
string
$ean
-
string
$type: type of EAN: {default: EAN13} EAN8,EAN13,EAN14,UPC12,ILN,NVE18
validate email address format
bool
checkEmail
(string $email, [bool $with_dns = false])
-
string
$email: email address
-
bool
$with_dns: true for dns check {default: false} (only works on non-windows platforms)
check if a string has HTML tags
bool
checkHtmlTag
(string $str)
-
string
$str: string to validate
validate IP address
bool
checkIP
(string $addr)
-
string
$addr: IP address to validate
validate MAC address
bool
checkMAC
(string $addr)
-
string
$addr: MAC address to validate
is string a valid number?
bool
checkNumber
(string $number, [char $sep = "."], [bool $mode = true], [bool $with_null = true])
-
string
$number: number to validate
-
char
$sep: valid seperator {default: "."}
-
bool
$mode: if true, with negative numbers {default: true}
-
bool
$with_null: if true, number "0" is valid {default: true}
validate number (positiv) with wildcards
bool
checkNumWildcard
(string $number, [char $sep = ","])
-
string
$number: number to validate
-
char
$sep: valid seperator {default: ","}
validate password format
bool
checkPassword
(string $password, [int $min_length = 5], int $strength)
-
string
$password: password string
-
int
$min_length: minimal length of password {default: 5}
-
int
$strength: 0: no special rules {default} 1: at least one number and one char 2: same as 1 and at least one lowercase and and uppercase letter 3: same as 2 and at least one special character
validate phone number
bool
checkPhone
(string $phone, [bool $mode = false])
-
string
$phone: phone number to validate
-
bool
$mode
validate string with letters only
bool
checkString
(string $str, [bool $mode = false])
-
string
$str: tring to validate
-
bool
$mode: true for German Umlaute include {default: false}
validate user name (only alpha-numeric, '_' and '-' (but not as first sign, because some systems has problems with this) are allowed)
bool
checkUserName
(string $user_name, [int $min_length = 3], [bool $allow_upper_case = true])
-
string
$user_name: user to validate
-
int
$min_length: minimal length of username {default: 3}
-
bool
$allow_upper_case: true : case insensitive {default: true} false : upper letters are not allowed
validate post zip code
bool
checkZip
(string $zip)
-
string
$zip: zip to validate
checks version of php and if pear is installed
bool
check_php_version
(string $min_ver, [bool $with_pear = false], [bool $mode = false])
-
string
$min_ver: oldest php version, which is allowed
-
bool
$with_pear: true: if pear must installed {default: false}
-
bool
$mode: true: die with message {default: false}
Convert date format
string
convDate
(string $date_str, string $src_format, string $dest_format, [array $customize = null])
-
string
$date_str: date to convert
-
string
$src_format: see member variables $this->date_format above
-
string
$dest_format: see member variables $this->date_format above or 'short' or 'long'
-
array
$customize: year_format string = long : e.g. 2002 {default} short: e.g. 02 void : e.g. leading_zeros bool = true : e.g. 01 {default} false: e.g. 1 with_weekday bool = true: with weekday false: without weekdays (only available if dest_format is short or long) locale string = see member variables m_locale above first_valid_year = first valid year, if specified date is before, it will be signed as invalid {default: 1850} short_mode = if today, yesterday or tomorrow show string for date {default: false}
convert datetime format
string
convDateTime
(string $datetime, [char $date_format = ""], [char $time_format = ""], [bool $with_seconds = false], [bool $short_mode = true], [string $at = null])
-
string
$datetime: db datetime field format
-
char
$date_format: see member variable m_date above
-
char
$time_format: see member variable m_time above
-
bool
$with_seconds: show seconds
-
bool
$short_mode: if today, yesterday or tomorrow show string for date
-
string
$at
convert first letter to upper or lower
string
convFirstLetter
(string $str, [bool $mode = false])
-
string
$str: string to convert
-
bool
$mode: true for upper, false for lower
convert ascii string to HTML string (because of a bug, it is better to set magic_quotes_gpc=Off in your php.ini)
string
convHtml
(string $str, [bool $mode = false], [bool $with_trim = true], [bool $with_link = false])
-
string
$str: string to convert
-
bool
$mode: true : html->ascii false: ascii->html {default}
-
bool
$with_trim: true : cut off whitespaces before and after the string {default} false: leave string with whitespaces
-
bool
$with_link: true : allow HTML links (you have to use [url=http://mydomain.com/]thebest[/url] syntax or [mail=me@mydomain.com]Me[/mail] (at the moment it works only in ascii->html)) false: disallow HTML links {default}
convert seperator in number and fill number to specified length
string
convnumSep
(float $st, [char $sep_new = "."], int $precision, [string $group = null])
-
float
$st: number to convert
-
char
$sep_new: new seperator {default: "."}
-
int
$precision: numbers behind seperator {default: 0 } (filling with 0; this function doesn't cut or round numbers)
-
string
$group: if set, this group seperator will be used
validate time format and convert it into right format
string
convTime
(string $time, [char $time_format = null], [bool $with_seconds = true])
-
string
$time: time to convert
-
char
$time_format: see member variable $this->time_format above
-
bool
$with_seconds: if false, don't return seconds {default: true}
convert string to number while converting old seperator with "."
float
convToNum
(string $value, [string $sep_old = ","])
-
string
$value: string to convert {default: ","}
-
string
$sep_old: old seperator
validate time format and convert it into right format
string
convToTimestamp
([string $time = ""], [char $format = ""])
-
string
$time: time (or date) to convert, if empty NOW will be used
-
char
$format: if empty or time, e.g. 19:45:59 datetime, e.g. 2002-07-20 21:02:55
convert German Umlaute to HTML and vice versa
string
convUmlaute
(string $str, [bool $mode = true])
-
string
$str: string to convert
-
bool
$mode: true: convert to HTML false: from HTML
checks for protocol, if missing http will be used
string
convUrl
(string $url)
counts days till specified day
int
countdown
(date $enddate)
Return cross sum of a number
int
cross_sum
(int $number)
the current date
date
currentDate
([char $date_format = null])
-
char
$date_format: see member variables $this->date_format below
the current time
time
currentTime
([char $time_format = null])
-
char
$time_format: see member variable $this->time_format below
calculates days to a given date
int
date2days
(date $start_date, date $end_date, [char $date_format = "S"])
-
date
$start_date: first date
-
date
$end_date: last date
-
char
$date_format: see member variables $this->date_format below
starts sub session within a session. You can use it to group the session in different parts Required : read README file
string
dbsessionsub_start
(string $session_id, [string $session_subid = ""])
-
string
$session_id: session id to use (main session)
-
string
$session_subid: session_subid. If empty new unique id will be generated if required
unregister variable in dbsession Required : read README file
bool
dbsession_delete
(string $session_id, string $var_name)
-
string
$session_id: session id which will be used for the variabel
-
string
$var_name: variable to remove
ends dbsession or dbsessionsub (Read the README file for requirements)
bool
dbsession_end
([string $session_id = ""])
-
string
$session_id: session id which should end ( and expired dbsession will automatically be removed)
register variable in dbsession
string
dbsession_read
(string $session_id, string $var_name)
-
string
$session_id: session id to use
-
string
$var_name: name of variable
starts dbsession. Enables session fallback handling. This functions
will be required, if you want to handle the session_id with url or formstart Required : read README file
string
dbsession_start
([string $session_id = ""], [bool $table_error = true])
-
string
$session_id: session id to use, if empty new unique id will be generated
-
bool
$table_error: show error message, if dbsession tables doesn't exist
register variable in dbsession Required : read README file
string
dbsession_write
(string $session_id, string $var_name, mixed $var_value)
-
string
$session_id: session id to use
-
string
$var_name: variable to add
-
mixed
$var_value: value of variable
disconnect current database connection (change $this->db for select the right one, if you use more the one connection)
bool
db_close
()
Opens a connection to a database server and select database Furthermore it sets $this->db to the PEAR database object, which is required for dbsession
object PEAR
db_connect
(string $dsn, [bool $set_db = true])
-
string
$dsn: Data Source Name ( for more information see PEAR documentation) addon array key: persistent = true for persistent {default: false}
-
bool
$set_db: if true, db object will be set to $this->db (and db_tyle and sql_like, too)
Get number of lowest unused number in a column)
int
db_free_id
(string $table, string $column, [string $where_key = ""], [string $where_value = ""])
-
string
$table: database table to use
-
string
$column: database column to use
-
string
$where_key: database column name for limitation {default: void}
-
string
$where_value: limitation value {default: void}
Get the id generated from the previous INSERT operation
int
db_insert_id
()
Get next available number
int
db_next_id
(string $table, string $column, [string $where = null])
-
string
$table: database table to use
-
string
$column: database column to use
-
string
$where: SQL WHERE restriction, e.g. "thisvalue>0" (without "WHERE" in string!)
Get next available number
int
db_seq_id
(string $seq_name)
-
string
$seq_name: name of sequence
check right database version
string
db_version
([float $mav = "3.23"], [float $miv = "6"])
-
float
$mav: major release number {default: 3.23}
-
float
$miv: minor release number {default: 6}
Return end tag for formular objects attending xhtml settings ($this->xhtml)
string
end_tag
()
return file extension
string
fileExtension
(string $filename)
Checks whether a file or directory exists (also checks the include_path in php.ini)
bool
file_exists
(string $filename)
generate password with specified characteristics
string
generate_password
([array $options = null])
-
array
$options: options array: min_length = min. length of password {default: 8} max_length = max. length of password {default: 8} exclude_signs = string with forbiddenen signs include_signs = string with signs, which have to been used exclude_pwd = this password is forbidden with_numbers = password has to use at least one number {true} with_lowers = password has to use at least one lower letter {true} with_uppers = password has to use at least one upper letter {true} with_signs = password has to use at least one special char {true}
Calculate active URL of an array for validation (can be used for multi URL sites (e.g. dyndns)
string
get_base_url
(mixed $urls)
-
mixed
$urls: an url or an array of urls
get the ip address from the client, even if the client is befind a proxy (it doesn't work with transparent proxy!)
string
get_client_ip
()
Cleanup text from invalid characters for filename
string
get_filename_from_text
(string $name)
calculates CSS font sizes. This is a small solution, that the appearance looks similar with different browser types and operating systems
array
get_fontsizes
([char $os_type = ""], [char $browser_type = ""])
-
char
$os_type: type of operating system {default: 'user agent os'}
-
char
$browser_type: type of browser {default: 'user agent os'}
create unique identification string
string
get_id_string
([bool $with_time = true])
-
bool
$with_time: true : with timestamp {default} false: without considering time and date
Return size of image file
int
get_image_size
(string $filename)
Get url for mod_rewrite
string
get_mod_rewrite_url
(string $prefix, int $id, [string $name = ""], [bool $invert_prefix = false], [string $extension = ".html"])
-
string
$prefix: prefix of URL
-
int
$id
-
string
$name
-
bool
$invert_prefix: if true, use prefix and id as suffix
-
string
$extension: file extention
returns value of special variable type from user input (If register_globals is Off (default since 4.2.0), this function can be used, to handle user variables (insecure variables).
You can use more than one type (seperated with ",") DBSESSION only works if dbsession_start has been called before.
mixed
get_user_var
(string $var_name, string $var_type)
-
string
$var_name: name of variable
-
string
$var_type: type of variable (POST, GET, COOKIE, SCRIPT, SESSION or DBSESSION) (note: SCRIPT means, declared variable above the function)
hit counter for web pages Required : every line in filename is a keyword, first line is the description (first line with quotes!!!)
int
hitcounter
(string $id, [bool $r = false], [bool $db_open = false], [array $CONF = null])
-
string
$id: id string
-
bool
$r: true: reload allowed false: reload disallowed {default}
-
bool
$db_open: true: database connection aready open false: no database connection open, open one
-
array
$CONF: CONF database array, if empty use counterconfig.php (have to be in same directory as cphplib.inc)
Write HTML head
string
html_head
(array $customize)
-
array
$customize: title charset no_cache lang seo with_header print
Setup HTML header
void
html_header
([array $customize = null])
-
array
$customize: charset set charset no_cache if true, page will not be cachable gzip if true, gzip compression will be used
search needle in multi array
bool
in_multi_array
(string $needle, array $haystack)
-
string
$needle
-
array
$haystack
Convert string to javascript compatible output
string
js_conv
(string $string)
Removes all whitespaces in a string
string
killSpace
(string $str)
prints a meta description and meta keywords line for xhtml Required : every line in filename is a keyword, first line is the description (first line with quotes!!!)
mixed
metatag_write
(string $filename, [bool $mode = true])
-
string
$filename: filename with keywords
-
bool
$mode: true: print it as meta tags {default} false: return array with text and keywords
check, if client IP or hostname is in access list
bool
net_access
([array $hosts = null], [array $ips = null], [bool $mode = "client"])
-
array
$hosts: array with hostnames, which have access
-
array
$ips: array with ips, which have access
-
bool
$mode: client, client ips (REMOTE_ADDR) {default} server, client ips (SERVER_ADDR) referrer (HTTP_REFERER)
returns type of operating system
char
os_type
([bool $mode = false])
-
bool
$mode: true for server os, false for client os {default: false}
pager (navigation) for list
string
pager
(string $url, [int $current_entry = null], [int $max_entries = null], [int $page_entries = null], [int $image_url = null])
-
string
$url: link for urls
-
int
$current_entry: current page number for navigation
-
int
$max_entries: highest page number in navigation
-
int
$page_entries: entries per page {default: $this->page_entries}
-
int
$image_url: overwrite global image url
generate rand string/number with specified length
string
rand_value
([int $length = 1], [string $values = ""])
-
int
$length: length of chars/numbers for return
-
string
$values: string with all allowed characters/numbers
removes magic quotes
void
remove_magic_quotes
(array &$array)
convert rgb to decimal color code
array
rgb2dec
(string $rgbstr)
-
string
$rgbstr: rgb string
Set date and time format to cphplib
void
set_format
(char $date_format, char $time_format)
-
char
$date_format: see $this->date_format for valid values
-
char
$time_format: see $this->time_format for valid values
Set locale
void
set_locale
()
Set strings for pager and Date methods
void
set_strings
()
Get date from db-date format (short form of convDate)
string
show_dbdate
(string $dbdate, [bool $short_mode = true])
-
string
$dbdate
-
bool
$short_mode
Get Datetime from db-date format (short form of convDate)
string
show_dbdatetime
(string $dbdate, [bool $with_seconds = false], [bool $short_mode = true], [string $at = null])
-
string
$dbdate
-
bool
$with_seconds
-
bool
$short_mode
-
string
$at
Show cphplib error
like error_level is defined
void
show_error
(string $function, string $message, [mixed $rc = null])
-
string
$function: cphplib function name
-
string
$message: error message
-
mixed
$rc: return code
Envelops a string with quotes (for db INSERT,UPDATES or SELECT)
string
sql_value
(string $str, [bool $conv_special_char = false], [int $active_null = 1])
-
string
$str: string to convert
-
bool
$conv_special_char: convert special charactar to html convention (great helper to secure SQL strings) {default: false} (conv_special_char is not recomended for an INSERT or UPDATE SQL string)
-
int
$active_null: 0: deactive NULL value 1: active NULL value {default} 2: active NULL value, with 0 is invalid
table header for all tables with optional sort support
string
table_header
(array $cols, int $default_col, string $sort, string $base_url, [array $customize = null])
-
array
$cols: colomns array
-
int
$default_col: default colomn
-
string
$sort: sort order
-
string
$base_url: base url for all links
-
array
$customize: bool $static true: don't use sort header false: sort header {default} bool $use_th true: th for table vill be used {default} false: td for table will be used int $max_entries if > 0: static mode, if max_entries < 2 {default: 2} string $mask if exists, it will be added on the end of the URL, e.g #mask string $tr_class CSS class for TR string $th_class CSS class for TD/TH
shorten text to given length for display
string
text_shorten
(string $text, int $max_length, [string $dots = "..."])
-
string
$text: text string
-
int
$max_length: maximum lenght of text
-
string
$dots: hars for dots {default: ...}
prints url as html tag (this function can only handle the session_id, if dbsession_start has been called immediately after creating the class object)
string
url
(string $url, [string $name = ""], [int $mode = 1], [string $title = ""], [string $customize = ""])
-
string
$url: url
-
string
$name: name of url {default: url}
-
int
$mode: 0: no session_id 1: with session_id if required {default: 1} 2: just url with session_id (without TAG) 3: just url with session_id (without TAG), but with delimiter & instead of & 4: with session_id (always)
-
string
$title: url title (hover text)
-
string
$customize: other parameters like target, style or class
checks if specified url is on script server (on the host where your scripts are)
bool
url_on_scripthost
(string $url)
validate given date
timestamp
validate_timestamp
(mixed $timestamp, [bool $mode = false])
-
mixed
$timestamp: array of date for validating or timestamp array keys: timestamp['year'] timestamp['month'] timestamp['day'] timestamp['hour'] timestamp['minute'] timestamp['second']
-
bool
$mode: if true, input date is a timestamp {default: false}