dolibarr 24.0.0-beta
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)
 Parse a stored phone number into country code and number parts.
 
 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 68 of file phone.lib.php.

References $db.

◆ 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 141 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 110 of file phone.lib.php.

References $db.

Referenced by Form\showPhoneInput().

◆ dol_parse_phone()

dol_parse_phone ( $phone)

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

Stored format is "+{code} {number}" (e.g. "+33 644986885"). If no code is found, returns empty code and the full string as number.

Parameters
string$phoneStored phone number
Returns
array{code:string,number:string} Array with 'code' and 'number' keys

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

Referenced by Form\showPhoneInput().