<?php

$format='(212) ### ### ##';
$phone='(212) 121 333 45';

// Quote any characters such as ( in the format so they match the input literally
// $regex == \(212\) ### ### ##
$regex = preg_quote($format, '/');

// Then surround any groups of #s with parens, making them capturing groups
// $regex == \(212\) (###) (###) (##)
$regex = preg_replace('/#+/', '(\0)', $regex);

// Finally, replace the placeholder # with \d and surround with quotes
// $regex == /\(212\) (\d\d\d) (\d\d\d) (\d\d)/
$regex = '/'.str_replace('#', '\d', $regex).'/';

if (preg_match($regex, $phone, $matches)) {
    echo "Matched: ".implode('', array_slice($matches, 1));
}
else {
    echo "No match";
}