dolibarr 25.0.0-alpha
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_all_trunk_prefixes ($db)
 Get the list of all distinct national trunk prefixes known in llx_c_country.
 
 dol_natural_search_phone ($db, $fields, $value, $nofirstand=0)
 Build a natural_search() SQL fragment for a phone/fax field, tolerant of the international storage format "+{code} {number}" vs a national search input (e.g.
 
 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 69 of file phone.lib.php.

◆ dol_get_all_trunk_prefixes()

dol_get_all_trunk_prefixes ( $db)

Get the list of all distinct national trunk prefixes known in llx_c_country.

Parameters
DoliDB$dbDatabase handler
Returns
string[] List of distinct non-empty trunk prefixes (e.g. array('0','1','8','06'))

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

Referenced by dol_natural_search_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 208 of file phone.lib.php.

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 111 of file phone.lib.php.

Referenced by Form\showPhoneInput().

◆ dol_natural_search_phone()

dol_natural_search_phone ( $db,
$fields,
$value,
$nofirstand = 0 )

Build a natural_search() SQL fragment for a phone/fax field, tolerant of the international storage format "+{code} {number}" vs a national search input (e.g.

searching "0645821542" must still match stored "+33 645821542").

Parameters
DoliDB$dbDatabase handler
string | string[]$fieldsField(s) to search, same as natural_search()
string$valueRaw value entered by the user
int$nofirstand1=Do not output the first 'AND'
Returns
string SQL to append to the query ('' if no value)
Returns
bool

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

References $c, dol_get_all_trunk_prefixes(), and natural_search().

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

Referenced by Form\showPhoneInput().