PHP – How to Show Persian or Arabic Numbers in Magento

ce-1.8.1.0csshtmljavascriptPHP

how to convert English numbers to persian/arabic numbers in Magento? (in all frontend)

i got this but i don't know how to use it or where to copy it.

function fanum($englishnumbers)
{
$englishnumbers = str_replace(’0′ , ‘PN’ , $englishnumbers);
$englishnumbers = str_replace(’1′ , ‘PN’ , $englishnumbers);
$englishnumbers = str_replace(’2′ , ‘PN’ , $englishnumbers);
$englishnumbers = str_replace(’3′ , ‘PN’ , $englishnumbers);
$englishnumbers = str_replace(’4′ , ‘PN’ , $englishnumbers);
$englishnumbers = str_replace(’5′ , ‘PN’ , $englishnumbers);
$englishnumbers = str_replace(’6′ , ‘PN’ , $englishnumbers);
$englishnumbers = str_replace(’7′ , ‘PN’ , $englishnumbers);
$englishnumbers = str_replace(’8′ , ‘PN’ , $englishnumbers);
$englishnumbers = str_replace(’9′ , ‘PN’ , $englishnumbers);

return $englishnumbers;
}

"PN" will replaced by "persian or arabic numbers"

Best Answer

Simple solution would be to use Javascript. Since prices are wrapped in a span tag with some class/id. You can read those values and convert it to arabic number using window load event.

For english to arabic number conversion You can use some jQuery plugins:
http://www.jqueryscript.net/other/jQuery-Plugin-To-Convert-English-Numbers-To-Persian-persianumber.html

Solution:
File: app/design/frontend/[your-package]/[your-theme]/template/page/footer.phtml
Code:

<script type="text/javascript" src="<?php echo $this->getJsUrl('persianumber.min.js') ?>"></script>
<script type="text/javascript">
    jQuery.noConflict();
    jQuery(function(){
       jQuery('.price').persiaNumber('ar');
    });
</script>

Notes:
- Upload the jQuery plugin file: persianumber.min.js to js/ folder
- If you haven't loaded the jQuery file then load it.

Related Topic