Probably the worst way to pad a string...
Submitted by phrax on Tue, 2004-09-21 14:48.
Wonky Code
Everyday I find code examples that make me go WTF. This is a prime example of one. It is a function that takes an item's id number and generates a left zero padded string with the id number.
I guess nobody told them about the str_pad() function.
function getVanPic($item_id) { $pic_path = "/path/to/pic/dir"; if ($item_id >= 1000000) { $strPicName = $item_id; } else if ($item_id >= 100000) { $strPicName = "0".$item_id; } else if ($item_id >= 10000) { $strPicName = "00".$item_id; } else if ($item_id >= 1000) { $strPicName = "000".$item_id; } else if ($item_id >= 100) { $strPicName = "0000".$item_id; } else if ($item_id >= 10) { $strPicName = "00000".$item_id; } else { $strPicName = "000000".$item_id; } $strPicName1 = "w".$strPicName.".jpg"; if (file_exists($pic_path."/".$strPicName1)) { return "van/".$strPicName1; } $strPicName1 = "W".$strPicName.".JPG"; if (file_exists($pic_path."/".$strPicName1)) { return "van/".$strPicName1; } return ""; }