Reputation: 10868
sorry if this is irrelevance :-)
I need to write something in my html code to convert digits of form 0123456789
to ۰۱۲۳۴۵۶۷۸۹
(Persian digits uni06F0..uni06F9).
the number of visitors is generated by blog service. and I want to convert its digits to Arabic.
Counter:
تعداد بازدیدکنندگان : <BlogSky:Weblog Counter /> نفر
the Persian part of above code mean 'Number of visitors' and 'Persons' (from left to right). but digits are represented in latin (0123...). Is it possible to write something like a function in html? i want it to be a global one for using in weblogs.
Note: I don't know anything about web programming languages. I'm not sure about language of above code. (html?)
Upvotes: 1
Views: 266
Reputation: 44376
HTML only describes the structure of the document. You'll have to use JavaScript - a client-side language that allows you to do what you need, ie manipulate DOM tree - in that case.
Here you've got an example of code that replaces 0...9
into ۰...۹
in given String:
myString.replace(/\d/g, function(matches) {
return String.fromCharCode("\u06F0".charCodeAt(0) + (matches[0] * 1));
})
So basically what you need now is to fetch text from document and replace it by itself but modified with above code:
//HTML
<p id="digits">0123456789</p>
//JavaScript:
var text = document.getElementById("digits").firstChild;
text.nodeValue = text.nodeValue.replace(/\d/g, function(matches) {
return String.fromCharCode("\u06F0".charCodeAt(0) + (matches[0] * 1));
});
Upvotes: 1