Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to replace numbers in body to persian numbers?

Tags:

I want to convert every number in the html content to Persian numerals without other effects on page elements.

For example:

<div style='color: #c2c2c2'>   text number 1   <span>text number 2</span>   <div>     text number 3     <b>text number 4</b>     <a href='#page2'>text number 5</a>   </div> </div> 

be converted to:

<div style='color: #c2c2c2'>   text number ۱   <span>text number ۲</span>   <div>     text number ۳     <b>text number ۴</b>     <a href='#page2'>text number ۵</a>   </div> </div> 
let persian = array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'); let english = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); 

Thanks.

like image 310
Alireza41 Avatar asked Mar 06 '13 12:03

Alireza41


People also ask

How do I change a number to Persian in Word?

Go to File > Options > Advanced. Scroll down to the Show document content section - you will find the Numeral option. Set it to Context. Hope this helps.

How do you write a Persian number?

Persian numbering rules Digits from zero to nine are specific words, namely sefr (صفر) [0], yek (یک) [1], do (دو) [2], se (سه) [3], chahâr (چهار) [4], panj (پنج) [5], shesh (شش) [6], haft (هفت) [7], hasht (هشت) [8], and noh (نه) [9].

Does Farsi use Arabic numerals?

Persian takes its numbering system from the Eastern Arabic numerals (or “Indian numerals” in Arabic) but retains its own names for the numbers apart from zero.


1 Answers

You can use this method: (http://jsfiddle.net/A4NfG/1/)

persian={0:'۰',1:'۱',2:'۲',3:'۳',4:'۴',5:'۵',6:'۶',7:'۷',8:'۸',9:'۹'}; function traverse(el){     if(el.nodeType==3){         var list=el.data.match(/[0-9]/g);         if(list!=null && list.length!=0){             for(var i=0;i<list.length;i++)                 el.data=el.data.replace(list[i],persian[list[i]]);         }     }     for(var i=0;i<el.childNodes.length;i++){         traverse(el.childNodes[i]);     } } 
like image 137
haitaka Avatar answered Sep 30 '22 07:09

haitaka