briant Posted May 8, 2009 Share Posted May 8, 2009 I'm sure there's a function for this, I just don't know what it is. In the database I have a 13 character number. I want to add a dash after the 3rd number. 948-3750279853 I tried wordwrap, that kind worked but it added a dash after every 3rd. number_format is a no. I was going to do a substr twice but that's kind of sloppy. There must be a better way. Thanks for any help in advanced. Link to comment https://forums.phpfreaks.com/topic/157333-solved-add-a-character-inbetween/ Share on other sites More sharing options...
RichardRotterdam Posted May 8, 2009 Share Posted May 8, 2009 you can use substr to split it at a position and then put a dash in between Link to comment https://forums.phpfreaks.com/topic/157333-solved-add-a-character-inbetween/#findComment-829273 Share on other sites More sharing options...
thebadbad Posted May 8, 2009 Share Posted May 8, 2009 Another way to do it is with sscanf() and implode(): <?php $str = '9483750279853'; $str = implode(sscanf($str, '%3s%10s'), '-'); ?> Link to comment https://forums.phpfreaks.com/topic/157333-solved-add-a-character-inbetween/#findComment-829284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.