In the database i have a field in the customers table called customers_telephone.
i want the output the telephone number like this(555) 555-5555.
within this CMS (oscommerce) the output on invoice.php looks like this.
<td class="main"><?php echo $order->customer['telephone']; ?></td>
i found a code that may work:
<?php
function format_telephone($phone_number)
{
$cleaned = preg_replace('/[^[:digit:]]/', '', $phone_number);
preg_match('/(d{3})(d{3})(d{4})/', $cleaned, $matches);
return "({$matches[1]}) {$matches[2]}-{$matches[3]}";
}
?>
<?php echo format_telephone($customer_phone); ?>
but i am confused where to place this and what variables to insert, i only need the format, only here and for US phones only.
3
Answers
That’s ok.
In Invoice.php file make sure you have this following block of code before you use it in the
<td
So put his line of code above somewhere, then in this line of code make sure you have
That’s it. You need to have the function before you use it on the code. Let us know if you have additional issues.
You can use regular expression
If you have code for a function, for example:
This would echo ‘hey’.
Anyway, now to the point: you would want to run the following to echo the phone number.
Make sure that you add the function code before you try and call it!