Re: Easy Way.
| From: | Jason Sheets | Date: | Sun, 09 Mar 2003 21:26:28 +0000 |
| Subject: | Re: Easy Way. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-138883@lists.php.net to get a copy of this message | ||
Hello,
Use str_pad, the manual page is available at http://www.php.net/str_pad,
a short example would be:
$i = 3;
$i = str_pad($i, 5, "0", STR_PAD_LEFT);
This function is described in the PHP manual in the string functions
section, the manual is an excellent place to go first when questions
such as this arise.
Jason
On Sun, 2003-03-09 at 14:17, Vincent M. wrote:
> Hello,
>
> Is there an easy way to change an integer to a 5 caracters string.
> For example:
> $i = 3 ;
> $j = 110 ;
> After having changed them:
> $i = "00003" ;
> $j = "00110" ;
>
> Is there a php function to do so instead of doing this:
> if( ($i>0)&&($i<10)) {
> $i = "0000".$i ;
> } else if( ($i>9)&&($i<100)) {
> $i = "000".$i ;
> } else if( ($i>99)&&($i<1000)) {
> $i = "00".$i ;
> } etc...
>
> Thanks :-)
>
> Vincent.
--
Jason Sheets <jsheets@php.net>