OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Convert English Numbers to Persian

  • Thread starter Thread starter John Doe
  • Start date Start date
J

John Doe

Guest
I am using the following JavaScript to convert all the English numbers showing on my website to Persian.

I realize that there are several ways to go about this and I have looked online and tried a few, however, this script does what I want it to do and it was really easy to implement except I want the phone number and date in my footer to be excluded from the conversion and remain English.

Not sure how I go about this in my PHP/HTML page.

On the second note, when my site is loading for a couple of seconds the numbers appear in English and quickly convert to Persian. Just wondering if there was a way that I could reduce this delay?

Here is my code:


Code:
<script language="JavaScript" type="text/javascript">
var replaceDigits = function() {
var map =
[
"&\#1776;","&\#1777;","&\#1778;","&\#1779;","&\#1780;",
"&\#1781;","&\#1782;","&\#1783;","&\#1784;","&\#1785;"
]
document.body.innerHTML =
document.body.innerHTML.replace(
/\d(?=[^<>]*(<|$))/g,
function($0) { return map[$0] }
);
}
</script>

<script type="text/javascript">
window.onload = replaceDigits
</script>
<p>I am using the following JavaScript to convert all the English numbers showing on my website to Persian.</p>

<p>I realize that there are several ways to go about this and I have looked online and tried a few, however, this script does what I want it to do and it was really easy to implement except I want the phone number and date in my footer to be excluded from the conversion and remain English.</p>

<p>Not sure how I go about this in my PHP/HTML page.</p>

<p>On the second note, when my site is loading for a couple of seconds the numbers appear in English and quickly convert to Persian. Just wondering if there was a way that I could reduce this delay?</p>

<p>Here is my code:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code><script language="JavaScript" type="text/javascript">
var replaceDigits = function() {
var map =
[
"&\#1776;","&\#1777;","&\#1778;","&\#1779;","&\#1780;",
"&\#1781;","&\#1782;","&\#1783;","&\#1784;","&\#1785;"
]
document.body.innerHTML =
document.body.innerHTML.replace(
/\d(?=[^<>]*(<|$))/g,
function($0) { return map[$0] }
);
}
</script>

<script type="text/javascript">
window.onload = replaceDigits
</script></code></pre>
</div>
</div>
</p>
Continue reading...
 

Latest posts

I
Replies
0
Views
1
Isaac P. Liu
I
U
Replies
0
Views
1
user3658366
U
G
Replies
0
Views
1
Giampaolo Levorato
G
M
Replies
0
Views
1
Marcelo Rodrigo Nascimento
M
Top