Thursday, 15 November 2018

How to replace entire numbers in a website to persian numbers via PHP?

How to replace entire numbers in body or website html to persian numbers via PHP?
I want to replace all numbers in my website for all pages .

Code:

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;
}

My Code work for Client Side:

<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>

I need a Good and Easy Code for Server Side.



from How to replace entire numbers in a website to persian numbers via PHP?

No comments:

Post a Comment