3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Converts numbers in string from western to eastern Arabic numerals. * * @param string $str Arbitrary text * @return string Text with western Arabic numerals converted into eastern Arabic numerals. */ function arabic_w2e($str) { $arabic_eastern = array('٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'); $arabic_western = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); return str_replace($arabic_western, $arabic_eastern, $str); } /** * Converts numbers from eastern to western Arabic numerals. * * @param string $str Arbitrary text * @return string Text with eastern Arabic numerals converted into western Arabic numerals. */ function arabic_e2w($str) { $arabic_eastern = array('٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'); $arabic_western = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); return str_replace($arabic_eastern, $arabic_western, $str); } //*/ Test $x = strval(date("r")); echo arabic_w2e($x); // Outputs: ١٢٣٤٥٦٧٨٩٠ // echo arabic_e2w("١٢٣٤يناير٥٦٧٨٩٠"); // Outputs: 1234567890 //*/ ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R8BrO
function name:  (null)
number of ops:  10
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   INIT_FCALL                                               'date'
          1        SEND_VAL                                                 'r'
          2        DO_ICALL                                         $1      
          3        CAST                                          6  ~2      $1
          4        ASSIGN                                                   !0, ~2
   29     5        INIT_FCALL                                               'arabic_w2e'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $4      
          8        ECHO                                                     $4
   33     9      > RETURN                                                   1

Function arabic_w2e:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R8BrO
function name:  arabic_w2e
number of ops:  10
compiled vars:  !0 = $str, !1 = $arabic_eastern, !2 = $arabic_western
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        ASSIGN                                                   !1, <array>
   11     2        ASSIGN                                                   !2, <array>
   12     3        INIT_FCALL                                               'str_replace'
          4        SEND_VAR                                                 !2
          5        SEND_VAR                                                 !1
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $5      
          8      > RETURN                                                   $5
   13     9*     > RETURN                                                   null

End of function arabic_w2e

Function arabic_e2w:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R8BrO
function name:  arabic_e2w
number of ops:  10
compiled vars:  !0 = $str, !1 = $arabic_eastern, !2 = $arabic_western
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   22     1        ASSIGN                                                   !1, <array>
   23     2        ASSIGN                                                   !2, <array>
   24     3        INIT_FCALL                                               'str_replace'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !2
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $5      
          8      > RETURN                                                   $5
   25     9*     > RETURN                                                   null

End of function arabic_e2w

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.8 ms | 1399 KiB | 18 Q