From 723ffa6951ceeefdb4211b36ffa0ae7c2f23f798 Mon Sep 17 00:00:00 2001 From: farad-tech Date: Tue, 4 Nov 2025 23:37:03 +0330 Subject: [PATCH 1/3] Add to_english_numbers helper --- src/Illuminate/Support/helpers.php | 18 ++++++++++++++++++ tests/Support/SupportHelpersTest.php | 7 +++++++ 2 files changed, 25 insertions(+) diff --git a/src/Illuminate/Support/helpers.php b/src/Illuminate/Support/helpers.php index 0b07595e7ef2..16d3539e4a84 100644 --- a/src/Illuminate/Support/helpers.php +++ b/src/Illuminate/Support/helpers.php @@ -523,3 +523,21 @@ function with($value, ?callable $callback = null) return is_null($callback) ? $value : $callback($value); } } + +if (! function_exists('to_english_numbers')) { + /** + * Converting Persian/Arabic digits to English + * @param mixed $value + * @return string + */ + function to_english_numbers($value): string + { + return strtr($value, [ + '۰' => '0', '۱' => '1', '۲' => '2', '۳' => '3', '۴' => '4', + '۵' => '5', '۶' => '6', '۷' => '7', '۸' => '8', '۹' => '9', + '٠' => '0', '١' => '1', '٢' => '2', '٣' => '3', '٤' => '4', + '٥' => '5', '٦' => '6', '٧' => '7', '٨' => '8', '٩' => '9', + ]); + } +} + diff --git a/tests/Support/SupportHelpersTest.php b/tests/Support/SupportHelpersTest.php index aad594dfc719..f98c54d6afe9 100644 --- a/tests/Support/SupportHelpersTest.php +++ b/tests/Support/SupportHelpersTest.php @@ -1572,6 +1572,13 @@ public function testPregReplaceArray($pattern, $replacements, $subject, $expecte preg_replace_array($pattern, $replacements, $subject) ); } + + public function testToEnglishNumbersConvertsPersianAndArabicDigits() + { + $this->assertEquals('123', to_english_numbers('۱۲۳')); + $this->assertEquals('456', to_english_numbers('٤٥٦')); + } + } trait SupportTestTraitOne From 0bdfdf21a7660ed821cb47acf804ee1b106f28e0 Mon Sep 17 00:00:00 2001 From: farad-tech Date: Wed, 5 Nov 2025 01:21:22 +0330 Subject: [PATCH 2/3] Number::toEnglishFormat() helper added --- src/Illuminate/Support/Number.php | 11 +++++++++++ tests/Support/SupportNumberTest.php | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/src/Illuminate/Support/Number.php b/src/Illuminate/Support/Number.php index 11035b0b9827..2006e59b6346 100644 --- a/src/Illuminate/Support/Number.php +++ b/src/Illuminate/Support/Number.php @@ -439,4 +439,15 @@ protected static function ensureIntlExtensionIsInstalled() throw new RuntimeException('The "intl" PHP extension is required to use the ['.$method.'] method.'); } } + + /** + * Converting Persian/Arabic digits to English + * @param mixed $value + * @return bool|float|int + */ + public static function toEnglishFormat($value) + { + $numberFormatter = new NumberFormatter('ar-u-nu-latn', NumberFormatter::DECIMAL); + return $numberFormatter->parse($value); + } } diff --git a/tests/Support/SupportNumberTest.php b/tests/Support/SupportNumberTest.php index 7f7de7f3f1a2..a22c3155aa91 100644 --- a/tests/Support/SupportNumberTest.php +++ b/tests/Support/SupportNumberTest.php @@ -370,4 +370,11 @@ public function testParseFloat() $this->assertSame(1234.56, Number::parseFloat('1.234,56', locale: 'de')); $this->assertSame(1234.56, Number::parseFloat('1 234,56', locale: 'fr')); } + + #[RequiresPhpExtension('intl')] + public function testToEnglishFormat() + { + $this->assertEquals('123', Number::toEnglishFormat('۱۲۳')); + $this->assertEquals('456', Number::toEnglishFormat('٤٥٦')); + } } From 0000a3caca7eb9907b6ea54c5359176b9b2ddb06 Mon Sep 17 00:00:00 2001 From: Farhad Karami <79833598+farad-tech@users.noreply.github.com> Date: Wed, 5 Nov 2025 01:43:29 +0330 Subject: [PATCH 3/3] Update src/Illuminate/Support/helpers.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sebastian Hädrich <11225821+shaedrich@users.noreply.github.com> --- src/Illuminate/Support/helpers.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Illuminate/Support/helpers.php b/src/Illuminate/Support/helpers.php index 16d3539e4a84..b620423a5e9b 100644 --- a/src/Illuminate/Support/helpers.php +++ b/src/Illuminate/Support/helpers.php @@ -532,12 +532,7 @@ function with($value, ?callable $callback = null) */ function to_english_numbers($value): string { - return strtr($value, [ - '۰' => '0', '۱' => '1', '۲' => '2', '۳' => '3', '۴' => '4', - '۵' => '5', '۶' => '6', '۷' => '7', '۸' => '8', '۹' => '9', - '٠' => '0', '١' => '1', '٢' => '2', '٣' => '3', '٤' => '4', - '٥' => '5', '٦' => '6', '٧' => '7', '٨' => '8', '٩' => '9', - ]); + return Number::toEnglishFormat($value); } }