diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 39cefe6054fd..e3a4019c2c13 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -750,6 +750,10 @@ public static function matchAll($pattern, $subject) */ public static function padBoth($value, $length, $pad = ' ') { + if (function_exists('mb_str_pad')) { + return mb_str_pad($value, $length, $pad, STR_PAD_BOTH); + } + $short = max(0, $length - mb_strlen($value)); $shortLeft = floor($short / 2); $shortRight = ceil($short / 2); @@ -769,6 +773,10 @@ public static function padBoth($value, $length, $pad = ' ') */ public static function padLeft($value, $length, $pad = ' ') { + if (function_exists('mb_str_pad')) { + return mb_str_pad($value, $length, $pad, STR_PAD_LEFT); + } + $short = max(0, $length - mb_strlen($value)); return mb_substr(str_repeat($pad, $short), 0, $short).$value; @@ -784,6 +792,10 @@ public static function padLeft($value, $length, $pad = ' ') */ public static function padRight($value, $length, $pad = ' ') { + if (function_exists('mb_str_pad')) { + return mb_str_pad($value, $length, $pad, STR_PAD_RIGHT); + } + $short = max(0, $length - mb_strlen($value)); return $value.mb_substr(str_repeat($pad, $short), 0, $short);