I want to convert English digits (0,1,2,3,...) to Arabic digits (۰,۱,۲,۳,...) in content of some HTML document using a PHP function.
I wrote this function:
function en2ar($str) {
$ends = array('0','1','2','3','4','5','6','7','8','9');
$ards = array('۰','۱','۲','۳','۴','۵','۶','۷','۸','۹');
return str_replace($ends,$ards,$str);
}
but it converts all digits in document, while I want to convert only digits in content of document.
for example, I want to convert:
<h1 style="color: #333;">1</h1>
<div style="width: 180px;">2</div>
to:
<h1 style="color: #333;">۱</h1>
<div style="width: 180px;">۲</div>
but it converts to:
<h۱ style="color: #۳۳۳;">۱</h۱>
<div style="width: ۱۸۰px;">۲</div>
and makes the document invalid.