Re: Inserting leading 0 infront of a variable
| From: | Andrey Hristov | Date: | Thu, 28 Feb 2002 08:03:19 +0000 |
| Subject: | Re: Inserting leading 0 infront of a variable | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-86552@lists.php.net to get a copy of this message | ||
This seems an endless loop for me. You do not alter the $myrowp[topic_id] so its length is untouched
=> if it is <6 you will never
get away from the loop. May be you want this.
# create topic number 6 digit
$count=strlen($myrow[topic_id]) ;
while ($count-- < 6){
$leading_digits .= '0';
}
$topic_id = $leading_digits.$myrow[topic_id] ;
Best regards,
Andrey Hristov
----- Original Message -----
From: "Andy" <news.letters@gmx.de>
To: <php-general@lists.php.net>
Sent: Thursday, February 28, 2002 9:56 AM
Subject: [PHP] Inserting leading 0 infront of a variable
> Hi guys,
>
> is there a possibility to add a string in front of a veriable like the .=
> commands adds it to the end? I would like to create a 6 digit number out of
> a e.g. 2 digit one. Underneath is my not working code. Maybe someone knows
> how to solve that.
>
> Thanx Andy
>
> # create topic number 6 digit
> while (strlen($myrow[topic_id]) < 6){
> $leading_digits .= '0';
> }
> $topic_id = $leading_digits.$myrow[topic_id] ;
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>