a small string question
Posted: Thu Mar 06, 2008 4:08 am
I have a sting like "03335240141" i want display it like 0333-524-0141 is there any string function that can do this for me?
thank you
dizyn
thank you
dizyn
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
function format ($str) {
// Validate
if (!is_string ($str) || strlen ($str) != 11) {
return false;
}
// Format
return substr ($str, 0, 4) . "-" . substr ($str, 4, 3) . "-" . substr ($str, 7);
}Code: Select all
function formatID ($id)
{
return preg_replace('#(\d{4})(\d{3})(\d{4})#', '$1-$2-$3', $id);
}Code: Select all
function formatID2($id)
{
return implode('-', str_split($id, 4));
}