1

I'm wondering if there is a programmatic way of detecting all instances of numbers on a web page (e.g. 1, 34, 558, 6, etc.) and convert them to equivalents in other languages of the site.

For example, if I have a bilingual site that has English and Arabic. On the English page there is a number "12345". It's coming from the database, so the numbers are stored as 12345 etc. in the database. Now, on the Arabic version of the site, I can translate all words etc. but numbers still show as 12345. I want to display Arabic numbers instead. It's impossible to translate the numbers because they are generated dynamically and keep changing.

I guess some sort of "on-the-fly" solution is what I'm looking for?

4

1 回答 1

0

我不相信在 HTML 中会有一种即时的方式,您将需要一种具有更多 umph 的语言,例如 Javascript 或 PHP。其他人将不得不向您展示一个 JS 示例,但对于 PHP,您可以这样做:

function eng_to_arabic($strTextToChange)
  {
    $strArabicNumbs = array('٩','٨','٧','٦','٥','٤','٣','٢','١','٠');
    $strEnglishNumbs = range(0, 9);

    return str_replace($strArabicNumbs, $strEnglishNumbs, $strTextToChange);
  }

然后你可以调用函数

echo eng_to_arabic($strSomeNumber);
于 2013-08-10T10:08:29.680 回答