dolibarr 24.0.3
phone.lib.php File Reference

Helper functions for phone number formatting. More...

Go to the source code of this file.

Functions

 dol_parse_phone ($phone, $db=null)
 Parse a stored phone number into country code and number parts.
 
 dol_get_all_phone_codes ($db)
 Get the list of all distinct phone codes known in llx_c_country.
 
 dol_build_phone ($db, $code, $number)
 Build a normalized phone string from code and number parts.
 
 dol_get_trunk_prefix ($db, $phone_code)
 Get the national trunk prefix for a phone code.
 
 dol_get_phone_code_from_country ($db, $country_id)
 Get the phone calling code for a country.
 

Detailed Description

Helper functions for phone number formatting.

Definition in file phone.lib.php.

Function Documentation

◆ dol_build_phone()

dol_build_phone ( $db,
$code,
$number )

Build a normalized phone string from code and number parts.

Strips formatting characters (spaces, dashes, dots, parentheses) from number. Also strips the national trunk prefix for the country matching $code (e.g. leading "0" for France, "8" for Russia, "06" for Hungary). Returns "+{code} {number}" or just the number if code is empty.

Parameters
DoliDB$dbDatabase handler
string$codeCountry calling code (e.g. "+33")
string$numberPhone number (may contain formatting)
Returns
string Normalized phone string

Definition at line 112 of file phone.lib.php.

References $db.

◆ dol_get_all_phone_codes()

dol_get_all_phone_codes ( $db)

Get the list of all distinct phone codes known in llx_c_country.

Parameters
DoliDB$dbDatabase handler
Returns
string[] List of distinct phone codes, without "+" (e.g. array('33','32','1684'))

Definition at line 76 of file phone.lib.php.

References $db, dol_syslog(), and string.

Referenced by dol_parse_phone().

◆ dol_get_phone_code_from_country()

dol_get_phone_code_from_country ( $db,
$country_id )

Get the phone calling code for a country.

Parameters
DoliDB$dbDatabase handler
int$country_idCountry rowid
Returns
string Phone code (e.g. "+33") or empty string

Definition at line 185 of file phone.lib.php.

References $db.

Referenced by Form\showPhoneInput().

◆ dol_get_trunk_prefix()

dol_get_trunk_prefix ( $db,
$phone_code )

Get the national trunk prefix for a phone code.

Parameters
DoliDB$dbDatabase handler
string$phone_codePhone code (e.g. "+33")
Returns
string Trunk prefix (e.g. "0") or empty string

Definition at line 154 of file phone.lib.php.

References $db.

Referenced by Form\showPhoneInput().

◆ dol_parse_phone()

dol_parse_phone ( $phone,
$db = null )

Parse a stored phone number into country code and number parts.

Stored format is "+{code} {number}" (e.g. "+33 644986885"). A code glued to the number or followed by formatting (e.g. "+33644986885" or "+33(0)6 44 98 68 85", from imports or old data) is recognized when $db is provided, using the longest phone code known in llx_c_country. If no code is found, returns empty code and the full string as number.

Parameters
string$phoneStored phone number
?DoliDB$dbDatabase handler, used to recognize a code glued to the number
Returns
array{code:string,number:string} Array with 'code' and 'number' keys

Definition at line 37 of file phone.lib.php.

References $db, and dol_get_all_phone_codes().

Referenced by Form\showPhoneInput().