diff --git a/src/Builder.php b/src/Builder.php index 270b241..eefa3f3 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -121,7 +121,7 @@ protected function renderCell($contents, $alignment, $width) break; } - return str_pad($contents, $width, ' ', $type); + return $this->mb_str_pad($contents, $width, ' ', $type); } protected function calculateWidths() @@ -130,7 +130,7 @@ protected function calculateWidths() foreach (array_merge([$this->headers], $this->rows) as $row) { for ($i = 0; $i < count($row); $i++) { - $iWidth = strlen((string)$row[$i]); + $iWidth = mb_strlen((string)$row[$i]); if (( ! array_key_exists($i, $widths)) || $iWidth > $widths[$i]) { $widths[$i] = $iWidth; } @@ -178,5 +178,12 @@ protected function columnAlign($columnNumber) return 'L'; } - -} \ No newline at end of file + protected function mb_str_pad($input, $pad_length, $pad_string, $pad_style, $encoding = "UTF-8") { + return str_pad( + $input, + strlen($input) - mb_strlen($input, $encoding) + $pad_length, + $pad_string, + $pad_style + ); + } +}