2017-11-11 101 views
0

我寫了這個函數來將波斯語數字轉換成英文數字,​​但它返回給我的是和輸入數字(波斯語)相同的數字。用str_replace將波斯語數字轉換爲英文數字

它包含波斯數量的數組和我這樣定義的波斯數的範圍,我想,如果你想打印波斯,你必須使用字體波斯數量與英語與str_replace函數功能

function convert($string) { 
    $persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']; 
    $num = range(0, 9); 
    $englishNumbersOnly = str_replace($persian, $num, $string); 
    return $englishNumbersOnly; 
} 
+0

做工精細http://sandbox.onlinephpfunctions.com/code/19495b7f078be2868ee72cf31f378164fe282170 – Devon

回答

0

更換波斯號例如,您可以使用WYekan字體。

<?php 
$number =1234; 
?> 
<p style="font-family: WYekan;"><?php echo $number ?></p> 
0
<?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; 
    } 
?>