From 0a89d8e66213389385e7bf035d5102e22e7a07f9 Mon Sep 17 00:00:00 2001 From: jasir Date: Fri, 12 Oct 2012 00:40:13 +0200 Subject: [PATCH] fixed problem with Utf-8 string When string is utf-8 coded, strtolower breaks strings. mb_string should be used when available --- src/Faker/Provider/Base.php | 22 +++++++++++++++++++++- src/Faker/Provider/Internet.php | 4 ++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Faker/Provider/Base.php b/src/Faker/Provider/Base.php index 74526059..4430e618 100644 --- a/src/Faker/Provider/Base.php +++ b/src/Faker/Provider/Base.php @@ -126,4 +126,24 @@ class Base { return static::lexify(static::numerify($string)); } -} \ No newline at end of file + + /** + * Converts string to lowercase. + * Uses mb_string extension if available + * @param string $string String that should be converted to lowercase + * @return string + */ + public static function toLower($string) { + return extension_loaded('mbstring') ? mb_strtolower($string) : strtolower($string); + } + + /** + * Converts string to uppercase. + * Uses mb_string extension if available + * @param string $string String that should be converted to uppercase + * @return string + */ + public static function toUpper($string) { + return extension_loaded('mbstring') ? mb_strtoupper($string) : strtoupper($string); + } +} diff --git a/src/Faker/Provider/Internet.php b/src/Faker/Provider/Internet.php index 08a5293c..7f8284ed 100644 --- a/src/Faker/Provider/Internet.php +++ b/src/Faker/Provider/Internet.php @@ -70,7 +70,7 @@ class Internet extends \Faker\Provider\Base public function userName() { $format = static::randomElement(static::$userNameFormats); - return strtolower(static::bothify($this->generator->parse($format))); + return static::toLower(static::bothify($this->generator->parse($format))); } /** @@ -91,7 +91,7 @@ class Internet extends \Faker\Provider\Base $company = $companyElements[0]; $company = preg_replace('/\W/', '', $company); - return strtolower($company); + return static::toLower($company); } /**