lp__str_to_phone( $value, $separator="," )

Converts a string to a valid phone number by replacing alphabetic characters with their corresponding numeric keypad values.

Plugin

Namespace

Launchpad

Parameters

string

$value

The input string to be converted to a phone number.

Return

string

The resulting phone number string with alphabetic characters replaced by their numeric keypad values.

Source

File: \includes\lp-utility-functions.php

function lp__str_to_phone( $value ){
    $result=array();
    $value = str_replace(array('[',']','(',')'), '', strtolower($value));
    $keypad = array('a' => '2', 'b' => '2', 'c' => '2', 'd' => '3',
        'e' => '3', 'f' => '3', 'g' => '4', 'h' => '4',
        'i' => '4', 'j' => '5', 'k' => '5', 'l' => '5',
        'm' => '6', 'n' => '6', 'o' => '6', 'p' => '7',
        'q' => '7', 'r' => '7', 's' => '7', 't' => '8',
        'u' => '8', 'v' => '8', 'w' => '9', 'x' => '9',
        'y' => '9', 'z' => '9');

    for ($x=0; $x<strlen($value); $x++){
        $letter = $value[$x];
        if (isset($keypad[$letter]) ?  $keypad[$letter] : false ) $result[]= $keypad[$letter];
        else $result[]= $letter;
    }
    return implode('',$result);
}

Related

Use to format a date string according to the specified format and timezone.

Use to convert the first character of each word in a string to uppercase.

Use to escape single quotes in a string.

Use to parse an array serialized as a string and returns it as a concatenated string.