3v4l.org

run code in 300+ PHP versions simultaneously
<?php function reverseHebrew($text) { $words = array_reverse(explode(' ', $text)); foreach ($words as $index => $word) { if (isHebrew($word)) { $words[$index] = mbStrRev($word); } } return join(' ', $words); } function isHebrew($text) { for ($i = 0, $cnt = strlen($text); $i < $cnt; ++$i) { if (ord($text[$i]) > 127) { return true; } } return false; } function mbStrRev($string, $encoding = null) { if ($encoding === null) { $encoding = mb_detect_encoding($string); } $length = mb_strlen($string, $encoding); $reversed = ''; while ($length-- > 0) { $reversed .= mb_substr($string, $length, 1, $encoding); } return $reversed; } $name = "אַבְרָהָם"; $newName = "Alexander Manukian"; echo reverseHebrew($newName);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cWjRi
function name:  (null)
number of ops:  7
compiled vars:  !0 = $name, !1 = $newName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   ASSIGN                                                   !0, '%D7%90%D6%B7%D7%91%D6%B0%D7%A8%D6%B8%D7%94%D6%B8%D7%9D'
   40     1        ASSIGN                                                   !1, 'Alexander+Manukian'
   42     2        INIT_FCALL                                               'reversehebrew'
          3        SEND_VAR                                                 !1
          4        DO_FCALL                                      0  $4      
          5        ECHO                                                     $4
          6      > RETURN                                                   1

Function reversehebrew:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 22
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 22
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 21
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 21
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/cWjRi
function name:  reverseHebrew
number of ops:  29
compiled vars:  !0 = $text, !1 = $words, !2 = $word, !3 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'array_reverse'
          2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '+'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $4      
          6        SEND_VAR                                                 $4
          7        DO_ICALL                                         $5      
          8        ASSIGN                                                   !1, $5
    6     9      > FE_RESET_R                                       $7      !1, ->22
         10    > > FE_FETCH_R                                       ~8      $7, !2, ->22
         11    >   ASSIGN                                                   !3, ~8
    7    12        INIT_FCALL_BY_NAME                                       'isHebrew'
         13        SEND_VAR_EX                                              !2
         14        DO_FCALL                                      0  $10     
         15      > JMPZ                                                     $10, ->21
    8    16    >   INIT_FCALL_BY_NAME                                       'mbStrRev'
         17        SEND_VAR_EX                                              !2
         18        DO_FCALL                                      0  $12     
         19        ASSIGN_DIM                                               !1, !3
         20        OP_DATA                                                  $12
    6    21    > > JMP                                                      ->10
         22    >   FE_FREE                                                  $7
   11    23        INIT_FCALL                                               'join'
         24        SEND_VAL                                                 '+'
         25        SEND_VAR                                                 !1
         26        DO_ICALL                                         $13     
         27      > RETURN                                                   $13
   12    28*     > RETURN                                                   null

End of function reversehebrew

Function ishebrew:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 5
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 15, Position 2 = 5
Branch analysis from position: 15
Branch analysis from position: 5
filename:       /in/cWjRi
function name:  isHebrew
number of ops:  17
compiled vars:  !0 = $text, !1 = $i, !2 = $cnt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   16     1        ASSIGN                                                   !1, 0
          2        STRLEN                                           ~4      !0
          3        ASSIGN                                                   !2, ~4
          4      > JMP                                                      ->13
   17     5    >   INIT_FCALL                                               'ord'
          6        FETCH_DIM_R                                      ~6      !0, !1
          7        SEND_VAL                                                 ~6
          8        DO_ICALL                                         $7      
          9        IS_SMALLER                                               127, $7
         10      > JMPZ                                                     ~8, ->12
   18    11    > > RETURN                                                   <true>
   16    12    >   PRE_INC                                                  !1
         13    >   IS_SMALLER                                               !1, !2
         14      > JMPNZ                                                    ~10, ->5
   21    15    > > RETURN                                                   <false>
   22    16*     > RETURN                                                   null

End of function ishebrew

Function mbstrrev:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 15
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 15
Branch analysis from position: 25
Branch analysis from position: 15
Branch analysis from position: 8
filename:       /in/cWjRi
function name:  mbStrRev
number of ops:  27
compiled vars:  !0 = $string, !1 = $encoding, !2 = $length, !3 = $reversed
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   26     2        TYPE_CHECK                                    2          !1
          3      > JMPZ                                                     ~4, ->8
   27     4    >   INIT_FCALL                                               'mb_detect_encoding'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $5      
          7        ASSIGN                                                   !1, $5
   30     8    >   INIT_FCALL                                               'mb_strlen'
          9        SEND_VAR                                                 !0
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $7      
         12        ASSIGN                                                   !2, $7
   31    13        ASSIGN                                                   !3, ''
   32    14      > JMP                                                      ->22
   33    15    >   INIT_FCALL                                               'mb_substr'
         16        SEND_VAR                                                 !0
         17        SEND_VAR                                                 !2
         18        SEND_VAL                                                 1
         19        SEND_VAR                                                 !1
         20        DO_ICALL                                         $10     
         21        ASSIGN_OP                                     8          !3, $10
   32    22    >   POST_DEC                                         ~12     !2
         23        IS_SMALLER                                               0, ~12
         24      > JMPNZ                                                    ~13, ->15
   36    25    > > RETURN                                                   !3
   37    26*     > RETURN                                                   null

End of function mbstrrev

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
202.86 ms | 1406 KiB | 28 Q