bgirls Posted March 25, 2006 Share Posted March 25, 2006 Hi Everyone!I have a question. How do I insert characters into a string before I echo it to the browser?In my database, I store phone numbers as 10 digit numbers (5555555555)Assuming that I extract a row from the database and now the following is true:$row[phone] is equal to 5555555555But I need to know how to insert a hyphen after the third and sixth character so I can echo it as:555-555-5555If anyone can help, I would appreciate it. Thanks! Link to comment https://forums.phpfreaks.com/topic/5766-solved-formatting-for-output/ Share on other sites More sharing options...
Barand Posted March 25, 2006 Share Posted March 25, 2006 First you need to split it into the 3 parts[code]$a = substr ($row['phone'], 0, 3);$b = substr ($row['phone'], 3, 3);$c = substr ($row['phone'], 6, 4);echo "$a-$b-$c";[/code] Link to comment https://forums.phpfreaks.com/topic/5766-solved-formatting-for-output/#findComment-20550 Share on other sites More sharing options...
bgirls Posted March 25, 2006 Author Share Posted March 25, 2006 [!--quoteo(post=358221:date=Mar 25 2006, 09:59 AM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Mar 25 2006, 09:59 AM) [snapback]358221[/snapback][/div][div class=\'quotemain\'][!--quotec--]First you need to split it into the 3 parts[code]$a = substr ($row['phone'], 0, 3);$b = substr ($row['phone'], 3, 3);$c = substr ($row['phone'], 6, 4);echo "$a-$b-$c";[/code][/quote]Works like a charm. Exactly what I needed. Thanks, Barand! Link to comment https://forums.phpfreaks.com/topic/5766-solved-formatting-for-output/#findComment-20561 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.