如何通过
PHP将身体或网站html中的整个数字替换为波斯数字?
我想替换我网站上所有页面的所有数字.
我想替换我网站上所有页面的所有数字.
码:
function ta_persian_num($string) { //arrays of persian and latin numbers $persian_num = array('۰','۱','۲','۳','۴','۵','۶','۷','۸','۹'); $latin_num = range(0,9); $string = str_replace($latin_num,$persian_num,$string); return $string; }
我的代码适用于客户端:
<script> $(document).ready(function(){ persian={0:'۰',1:'۱',2:'۲',3:'۳',4:'۴',5:'۵',6:'۶',7:'۷',8:'۸',9:'۹'}; function traverse(el){ if(el.nodeType==3){ var list=el.data.match(/[0-9]/g); if(list!=null && list.length!=0){ for(var i=0;i<list.length;i++) el.data=el.data.replace(list[i],persian[list[i]]); } } for(var i=0;i<el.childNodes.length;i++){ traverse(el.childNodes[i]); } } traverse(document.body); }); </script>
您最好将此功能移至前端使用javascript:
原文链接:https://www.f2er.com/php/133716.html<script 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]}); } window.onload = replaceDigits; </script>
例如:https://codepen.io/anon/pen/rQWGRd
<body onload="replaceDigits()">