Jump to content

4564564566 to (456) 456-4566


tibberous

Recommended Posts

Credits to Barand:  (with a slight modification)

 

<?php
function format_template($str, $template) {
    $str = str_replace(' ', '', $str);
    $kt = strlen($template);
    $ks = strlen($str);
    $res = '';
    $j = 0;
    for($i=0; $i<$kt; $i++) {
        if ($j==$ks) break;
        switch ($c = $template[$i]) {
            case '#':
                $res .= $str[$j++];
                break;
            case '!':
                $res .= strtoupper($str[$j++]) ;
                break;
            default:
                $res .= $c;
                break;
        }
    }
    return $res;
}

 

Usage:

<?php
$foo = format_template('4564564566', '(###) ###-4566');
echo $foo;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.