25 lines
698 B
PHP
25 lines
698 B
PHP
<?php
|
||
|
||
namespace App\Support;
|
||
|
||
class PersianDigits
|
||
{
|
||
public static function toEnglish(mixed $value): mixed
|
||
{
|
||
if (is_string($value)) {
|
||
$persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
|
||
$arabic = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];
|
||
$latin = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
||
$value = str_replace(array_merge($persian, $arabic), array_merge($latin, $latin), $value);
|
||
|
||
return str_replace('٫', '.', $value);
|
||
}
|
||
|
||
if (is_array($value)) {
|
||
return array_map([self::class, 'toEnglish'], $value);
|
||
}
|
||
|
||
return $value;
|
||
}
|
||
}
|