OnlineSolution Forum IndexOnlineSolution Forum Index
OnlineSolution
FAQ  FAQ   Search  Search   Memberlist  Memberlist   Usergroups  Usergroups   Register  Register  
Register::  Log in Log in to check your private messages


 Advertisement

Post new topic  Reply to topic
 [ PHP ] PHP Custom Function - zero_fill() « View previous topic :: View next topic » 
Author Message
Paul
PostPosted: Tue Feb 02, 2010 10:04 pm    Post subject: PHP Custom Function - zero_fill() Reply with quote

Site Admin

Joined: 10 Dec 2007
Posts: 143
Location: New Zealand

Sometimes you'll need add zeros (0000) in front of some integers such as invoice number followed by certain numbering rules - zero fill - to make it look better on invoices / quotations / etc.

PHP does not natively support zerofill functions but the following customer function will let you use zero fill function with a few lines of codes:

Code:
<?php

function zero_fill($number,$padding)
{
    return str_pad($number, $padding, "0", STR_PAD_LEFT);
}

echo zero_fill(3123,10);

?>

From echo zero_fill(3123,10);, 3123 is actual integer you want to display, 10 is the number of digits (paddings) you want to display.
_________________
Paul KH Kim

http://www.onlinesolution.co.nz
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

 Sponsor Link

Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



OnlineSolution - Since 2007
DAJ Glass (1.0.8) template by Dustin Baccetti
EQ graphic based off of a design from www.freeclipart.nu
Powered by phpBB © 2001, 2005 phpBB Group