do you know how can i put a hyphen (-) after 3 digits of a number(starting from the end) in php? example: the number 9787897878 to be shown as 978-789-7878??

Recommended Answers

All 2 Replies

Something like this:

$subject = '9787897878';
$result = preg_replace('/(\d{3})(\d{3})(\d*)/i', '\1-\2-\3', $subject);
echo $result;

preg_replace("/^(\d{3})(\d{3})(\d{4})$/", "$1-$2-$3", $phone):'')

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.