nintondo Posted August 31, 2009 Share Posted August 31, 2009 hi i need help in appending a format to a string eg. given number : 123 desired outcome--->000/000/000/000/123 number : 12345 desired outcome---> 000/000/000/012/345 meaning every 3 numbers @ the back is prepended with a '/' how do I go about doing this? Link to comment https://forums.phpfreaks.com/topic/172562-appending-format/ Share on other sites More sharing options...
emehrkay Posted August 31, 2009 Share Posted August 31, 2009 Start here http://us2.php.net/manual/en/function.sprintf.php Link to comment https://forums.phpfreaks.com/topic/172562-appending-format/#findComment-909665 Share on other sites More sharing options...
PFMaBiSmAd Posted August 31, 2009 Share Posted August 31, 2009 function your_format($number){ $string = str_pad($number, 15, '0', STR_PAD_LEFT); $array = str_split($string, 3); $result = implode('/', $array); return $result; } echo your_format(123); echo "<br />"; echo your_format(12345); Link to comment https://forums.phpfreaks.com/topic/172562-appending-format/#findComment-909671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.