Hello,
Ive created an array form a query which contains numbers like 5 , 45, 2, 846
But i should have it as 00005 , 00045 , 00002, 00846
What kind of instrucitions whould do this in a nice way...?
THx
adding zeroes in front
Moderator: General Moderators
From the manual.. http://www.php.net/str_pad
So...
May be close to what your looking for
But even after you pad it, you will need to ensure that it's treated as a string..
Otherwise the 0's may be removed..
Code: Select all
<?php
$input = "Alien";
echo str_pad($input, 10); // produces "Alien "
echo str_pad($input, 10, "-=", STR_PAD_LEFT); // produces "-=-=-Alien"
echo str_pad($input, 10, "_", STR_PAD_BOTH); // produces "__Alien___"
echo str_pad($input, 6 , "___"); // produces "Alien_"
?>Code: Select all
echo str_pad($input, 5, "0", STR_PAD_LEFT);But even after you pad it, you will need to ensure that it's treated as a string..
Code: Select all
$input = (string) $input;