9951 explained code solutions for 126 technologies


phpConvert standard numbers to Persian numbers


function fa_number($number)
{
  if ( !is_numeric($number) || empty($number) ) return '۰';
  
  $en = array("0","1","2","3","4","5","6","7","8","9");
  $fa = array("۰","۱","۲","۳","۴","۵","۶","۷","۸","۹");
  
  return str_replace($en, $fa, $number);
}ctrl + c
fa_number

function name to use later

$en

list of standard numbers

$fa

list of corresponding Persian numbers


Usage example

<?php

function fa_number($number)
{
  if(!is_numeric($number) || empty($number)) return '۰';

  $en = array("0","1","2","3","4","5","6","7","8","9");
  $fa = array("۰","۱","۲","۳","۴","۵","۶","۷","۸","۹");

  return str_replace($en, $fa, $number);
}

echo fa_number(12345);
output
۱۲۳۴۵