Reputation: 242
i wrote this function to convert persian digits to english digits but it returns to me same as input digits(persian).
it contains an array of persian number and i defined an range like persian number and i want to replace persian number with english with str_replace function
function convert($string) {
$persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
$num = range(0, 9);
$englishNumbersOnly = str_replace($persian, $num, $string);
return $englishNumbersOnly;
}
Upvotes: 0
Views: 2072
Reputation: 153
Thanks to @meykan-jain answer, to parse Arabic and Persian both use this:
function parseNumber($string) {
$persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
$arabic = ['٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'];
$num = range(0, 9);
$englishNumbersOnly = str_replace($persian, $num, $string);
$englishNumbersOnly = str_replace($arabic, $num, $englishNumbersOnly);
return $englishNumbersOnly;
}
Upvotes: 0
Reputation: 84
<?php
$converted=convert('Any String as Input');
echo $converted;
function convert($string) {
$persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
$num = range(0, 9);
$englishNumbersOnly = str_replace($persian, $num, $string);
return $englishNumbersOnly;
}
?>
Upvotes: 1
Reputation: 1680
if you want to print number persian you must use font persian..for example you can use WYekan font.
<?php
$number =1234;
?>
<p style="font-family: WYekan;"><?php echo $number ?></p>
Upvotes: 0