diff --git a/composer.json b/composer.json index eff5f00..59e5d25 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "require": { "php": ">=5.4.0", "illuminate/support": "4.*", - "illuminate/container": "4.*" + "illuminate/container": "4.*", + "ext-mbstring": "*" }, "require-dev": { "phpunit/phpunit": "3.7.*", diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php index a1297ec..fd72a18 100644 --- a/src/Filter/Filter.php +++ b/src/Filter/Filter.php @@ -181,19 +181,42 @@ public function registerDefaultFilters() }); $this->registerFilter('upper', function($value, array $args) { - return strtoupper($value); + return mb_strtoupper($value); }); $this->registerFilter('lower', function($value, array $args) { - return strtolower($value); + return mb_strtolower($value); }); $this->registerFilter('capfirst', function($value, array $args) { - return ucfirst($value); + return $this->mb_ucfirst($value); }); $this->registerFilter('lowerfirst', function($value, array $args) { - return lcfirst($value); + return $this->mb_lcfirst($value); }); } + + /** + * @param $string + * @param string $encoding + * @return string + */ + protected function mb_ucfirst($string, $encoding = 'UTF-8') + { + $firstChar = mb_substr($string, 0, 1, $encoding); + $then = mb_substr($string, 1, null, $encoding); + return mb_strtoupper($firstChar, $encoding) . $then; + } + + /** + * @param $string + * @return string + */ + protected function mb_lcfirst($string, $encoding = 'UTF-8') + { + $firstChar = mb_substr($string, 0, 1, $encoding); + $then = mb_substr($string, 1, null, $encoding); + return mb_strtolower($firstChar, $encoding) . $then; + } } \ No newline at end of file