[thelist] PHP coding help

Charles F. Johnson charles at littlegreenfootballs.com
Fri Sep 7 10:55:22 CDT 2001


R.Livsey <R.Livsey at cache-22.co.uk> typed:

> /* pads a string $to_pad upto length $length padding with
> $pad_char. */
> function pad($to_pad, $length, $pad_char)
> {
> while (strlen($to_pad)<$length)
> {
>    $to_pad = $pad_char . $to_pad;
> }
> return $to_pad;
> }

Just a tip: your pad() function is really unnecessary, since PHP already has
the sprintf() function for this purpose. To left-pad a string with zeros,
you can use this:

$id = sprintf("%05d", $id);


charles johnson
lgf web design
http://littlegreenfootballs.com





More information about the thelist mailing list