I have a database field where a phone-number is stored as an integer value - it's 8 digits, like: 12345678 I would like to split this up when presenting it on the page, into 3 2 3 - ie: 123 45 678 for displaying. How can I do this the easiest way? I've pondered if preg_replace maybe is overkill, and was wondering if there is any simpler ways to split this string into 3 separate entities, or just somehow insert whitespace after the first 3 and the first 5 numbers. There will always be 8 digits in the field, but since it's being stored as an integer value, I cannot add whitespace to the database value. Anyone? EDIT: came up with this - it works, but is there an easier/prettier way to do this? $phone = substr($res_info['who_phone'],0,3); $phone .= " ".substr($res_info['who_phone'],3,2); $phone .= " ".substr($res_info['who_phone'],5,3); PHP:
ereg ("([0-9]{3})([0-9]{2})([0-9]{3})", '12345678', $part); echo "$part[1] - $part[2] - $part[3]"; PHP:
Thanks to both of you - I ended up using koko5s solution - less lines of code == good +Rep added to both