Reply to Re: Small problem with PHP

Your name:

Reply:


Posted by Tom on 05/25/07 17:55

<alpha.beta0@googlemail.com> wrote in message
news:1180112733.002880.170520@w5g2000hsg.googlegroups.com...
> I set it to 001 at start but the next number PHP produces is
> 2,3,4,5,etc. instead of 002,003,004,005,etc.
>
> What will I need to change to get the latter?
>
> ===
>
> $Count = 001;
>
> foreach($Replace_With_List as $Replace_With)
> {
> ++$Count;
> }
>
> ===
>


The problem is "001" is a string of text, not a real number. Maybe use the
"strlen" function to determine the length in characters, then add to the
beginning of the string if needed.


<?php
$Count = 1;
foreach($Replace_With_List as $Replace_With)
{
++$Count;
}

if(strlen($Count) == 1)
{
$Count = '00' . $count;
}
elseif(strnlen($Count) == 2)
{
$Count = '0' . $count;
}

?>

Tom
--
Newsguy Internet Access
$9.95 / mo. or $79.95 / yr.
http://newsguy.com/allinone.htm

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация