From be0b83c7b9a7a8cf91ef6799bede2d49cfa5a131 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 9 Jan 2013 05:17:43 +0000 Subject: [PATCH] More usage of padLeftZero() instead of prependZeros() but use prependZeros() as a fall-back if str_pad() is not available --- inc/libs/user_functions.php | 2 +- inc/wrapper-functions.php | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/inc/libs/user_functions.php b/inc/libs/user_functions.php index 2477532023..9a02c876fe 100644 --- a/inc/libs/user_functions.php +++ b/inc/libs/user_functions.php @@ -759,7 +759,7 @@ function getNextFreeTesterUserNumber () { $nextTester = getTotalTesterUsers(); // Prepend zeros - $nextTester = prependZeros($nextTester, 6); + $nextTester = padLeftZero($nextTester, 6); // Return it return $nextTester; diff --git a/inc/wrapper-functions.php b/inc/wrapper-functions.php index c936142288..1593901d6a 100644 --- a/inc/wrapper-functions.php +++ b/inc/wrapper-functions.php @@ -3245,9 +3245,9 @@ function determineWhat ($module = NULL) { } // Fills (prepend) a string with zeros. This function has been taken from user comments at de.php.net/str_pad -function prependZeros ($mStretch, $length = 2) { +function prependZeros ($str, $length = 2) { // Return prepended string - return sprintf('%0' . (int) $length . 's', $mStretch); + return sprintf('%0' . (int) $length . 's', $str); } // Wraps convertSelectionsToEpocheTime() @@ -3412,8 +3412,14 @@ function shift_array (&$array, $value, $key = '0') { // Wrapper for str_pad() with left padding zeros function padLeftZero ($str, $amount = 2) { - // Pad it - return str_pad($str, $amount, '0', STR_PAD_LEFT) + // Is str_pad() there? + if (function_exists('str_pad')) { + // Use prependZeros() + return prependZeros($str, $amount); + } else { + // Pad it + return str_pad($str, $amount, '0', STR_PAD_LEFT) + } } // [EOF] -- 2.39.5