How can I view Arabic/Persian numbers in a HTML pa

2019-01-27 16:23发布

I have an HTML page that is right-to-left. When I don't use any doctype, my numbers are in Arabic/Persian, but when I use strict mode they turn to English.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Final//EN">

Before adding doctype:

Before adding doctype

After adding doctype:

After adding doctype

also I added these meta tags to my page:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="fa" />

So how can I view Arabic numbers in a page with strict doctype (in IE because Firefox doesn't show Arabic numbers anyway)?

9条回答
ら.Afraid
2楼-- · 2019-01-27 16:27

This works for me, regardless of the text direction (in Chrome, Safari, Firefox and Opera):

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Final//EN">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <style type="text/css">
            body { direction: rtl; }
        </style>
    </head>

    <body>
        ۴۲
    </body>
</html>

(Omitted the content-language since that isn’t necessary here.)

查看更多
【Aperson】
3楼-- · 2019-01-27 16:30

It is very simple to view Arabic/Persian numbers in a HTML page.

I solved the same problem by changing the font name,

In my case I want to display the same character to all users

you can choose a font that contains Arabic-Hndi digits and import it using the css ( @font-face ) then simply use it,

This works fine for all major browsers (IE .. Firefox .. Chrome)

look at this result

here is the full code of the page:

<html>
<head>

</head>
<body>
<style type="text/css">

@font-face {
    font-family: ArabicTwo_Bold;
    src: url( ArabicTwo_Bold.eot);
}

@font-face {
    font-family: ArabicTwo_Bold;
    src: url( ArabicTwo_Bold.ttf);
}


div , input {
 font-family: ArabicTwo_Bold;
}
</style>


<input type='text' value='هذا نص هندي 123456 ' />
<div> هذا نص هندي 123456  </div>
</body>
</html>
查看更多
等我变得足够好
4楼-- · 2019-01-27 16:31

If you use persian fonts like 'BNazanin' and write :

http-equiv="Content-Type" content="text/html; charset=UTF-8"
and http-equiv="Content-Language" content="fa" in meta tags.

You can then see the numbers in persian.

and if you use lang='En' in some tags in your html page the numbers in that tag will be displayed in english.

查看更多
戒情不戒烟
5楼-- · 2019-01-27 16:33
var map_format_arabic = ["&\#1632;","&\#1633;","&\#1634;","&\#1635;","&\#1636;", "&\#1637;","&\#1638;","&\#1639;","&\#1640;","&\#1641;"];

$.each( $('.format_arabic'), function () {
    var n=$(this).text().replace(/\d(?=[^<>]*(<|$))/g, function($0) { return map_format_arabic[$0]});
    $(this).html(n);
});
查看更多
We Are One
6楼-- · 2019-01-27 16:38

try this , hope helps you ;)

between and

<script language="JavaScript" type="text/javascript">


var replaceDigits = function() {
var map =
[
"&\#1632;","&\#1633;","&\#1634;","&\#1635;","&\#1636;",
"&\#1637;","&\#1638;","&\#1639;","&\#1640;","&\#1641;"
]

document.body.innerHTML =
document.body.innerHTML.replace(
/\d(?=[^<>]*(<|$))/g,
function($0) { return map[$0] }
);
}

</script>

then in end of body tag insert this :

<script type="text/javascript">
window.onload = replaceDigits
</script>
查看更多
爱情/是我丢掉的垃圾
7楼-- · 2019-01-27 16:39

Assuming you want an XHTML 1.0 Strict document:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fa" lang="fa" dir="rtl">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Title here</title>
  </head>

  <body>
    <p>Text here</p>
  </body>
</html>

Here's an equivalent HTML 4.01 Strict document:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
<html lang="fa" dir="rtl">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Title here</title>
  </head>

  <body>
    <p>Text here</p>
  </body>
</html>

Here's an equivalent HTML5 page, just for comparison purposes.

<!DOCTYPE html>
<html lang="fa" dir="rtl">
  <head>
    <meta charset="UTF-8" />
    <title>Title here</title>
  </head>

  <body>
    <p>Text here</p>
  </body>
</html>
查看更多
登录 后发表回答