3v4l.org

run code in 300+ PHP versions simultaneously
<?php function letterToColumnNumber(string $letters, int $indexStart = 0): int { static $ordA = ord('A'); $length = strlen($letters); $number = 0; $pow = 1; for ($i = $length - 1; $i >= 0; $i--) { // calculate the value of each letter and add to the total $number += (ord($letters[$i]) - $ordA + 1) * $pow; $pow *= 26; } return $number - (1 - $indexStart); } function rangeStringToRangeArray(string $range, int $indexStart = 0): array { // Parse Excel range expression if (sscanf($range, '%[A-Z]%d:%[A-Z]%d', $startCol, $startRow, $endCol, $endRow) != 4) { throw new Exception('Invalid range expression'); } return [ [ letterToColumnNumber($startCol, $indexStart), $startRow - (1 - $indexStart) ], [ letterToColumnNumber($endCol, $indexStart), $endRow - (1 - $indexStart) ] ]; } echo json_encode(rangeStringToRangeArray('A1:B2')); // returns [[0,0],[1,1]] echo json_encode(rangeStringToRangeArray('A1:B2', 1)); // returns [[1,1],[2,2]]
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/679Dp
function name:  (null)
number of ops:  16
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   INIT_FCALL                                               'json_encode'
          1        INIT_FCALL                                               'rangestringtorangearray'
          2        SEND_VAL                                                 'A1%3AB2'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                         $1      
          6        ECHO                                                     $1
   39     7        INIT_FCALL                                               'json_encode'
          8        INIT_FCALL                                               'rangestringtorangearray'
          9        SEND_VAL                                                 'A1%3AB2'
         10        SEND_VAL                                                 1
         11        DO_FCALL                                      0  $2      
         12        SEND_VAR                                                 $2
         13        DO_ICALL                                         $3      
         14        ECHO                                                     $3
         15      > RETURN                                                   1

Function lettertocolumnnumber:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 11
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 11
Branch analysis from position: 23
Branch analysis from position: 11
filename:       /in/679Dp
function name:  letterToColumnNumber
number of ops:  29
compiled vars:  !0 = $letters, !1 = $indexStart, !2 = $ordA, !3 = $length, !4 = $number, !5 = $pow, !6 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
    5     2        ZEND_BIND_INIT_STATIC_OR_JMP                             !2
          3        BIND_STATIC                                              !2, 65
    6     4        STRLEN                                           ~7      !0
          5        ASSIGN                                                   !3, ~7
    7     6        ASSIGN                                                   !4, 0
    8     7        ASSIGN                                                   !5, 1
   10     8        SUB                                              ~11     !3, 1
          9        ASSIGN                                                   !6, ~11
         10      > JMP                                                      ->21
   12    11    >   INIT_FCALL                                               'ord'
         12        FETCH_DIM_R                                      ~13     !0, !6
         13        SEND_VAL                                                 ~13
         14        DO_ICALL                                         $14     
         15        SUB                                              ~15     $14, !2
         16        ADD                                              ~16     ~15, 1
         17        MUL                                              ~17     !5, ~16
         18        ASSIGN_OP                                     1          !4, ~17
   13    19        ASSIGN_OP                                     3          !5, 26
   10    20        PRE_DEC                                                  !6
         21    >   IS_SMALLER_OR_EQUAL                                      0, !6
         22      > JMPNZ                                                    ~21, ->11
   16    23    >   SUB                                              ~22     1, !1
         24        SUB                                              ~23     !4, ~22
         25        VERIFY_RETURN_TYPE                                       ~23
         26      > RETURN                                                   ~23
   17    27*       VERIFY_RETURN_TYPE                                       
         28*     > RETURN                                                   null

End of function lettertocolumnnumber

Function rangestringtorangearray:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/679Dp
function name:  rangeStringToRangeArray
number of ops:  38
compiled vars:  !0 = $range, !1 = $indexStart, !2 = $startCol, !3 = $startRow, !4 = $endCol, !5 = $endRow
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
   22     2        INIT_FCALL                                               'sscanf'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 '%25%5BA-Z%5D%25d%3A%25%5BA-Z%5D%25d'
          5        SEND_REF                                                 !2
          6        SEND_REF                                                 !3
          7        SEND_REF                                                 !4
          8        SEND_REF                                                 !5
          9        DO_ICALL                                         $6      
         10        IS_NOT_EQUAL                                             $6, 4
         11      > JMPZ                                                     ~7, ->16
   23    12    >   NEW                                              $8      'Exception'
         13        SEND_VAL_EX                                              'Invalid+range+expression'
         14        DO_FCALL                                      0          
         15      > THROW                                         0          $8
   28    16    >   INIT_FCALL                                               'lettertocolumnnumber'
         17        SEND_VAR                                                 !2
         18        SEND_VAR                                                 !1
         19        DO_FCALL                                      0  $10     
         20        INIT_ARRAY                                       ~11     $10
   29    21        SUB                                              ~12     1, !1
         22        SUB                                              ~13     !3, ~12
         23        ADD_ARRAY_ELEMENT                                ~11     ~13
         24        INIT_ARRAY                                       ~14     ~11
   32    25        INIT_FCALL                                               'lettertocolumnnumber'
         26        SEND_VAR                                                 !4
         27        SEND_VAR                                                 !1
         28        DO_FCALL                                      0  $15     
         29        INIT_ARRAY                                       ~16     $15
   33    30        SUB                                              ~17     1, !1
         31        SUB                                              ~18     !5, ~17
         32        ADD_ARRAY_ELEMENT                                ~16     ~18
         33        ADD_ARRAY_ELEMENT                                ~14     ~16
         34        VERIFY_RETURN_TYPE                                       ~14
         35      > RETURN                                                   ~14
   36    36*       VERIFY_RETURN_TYPE                                       
         37*     > RETURN                                                   null

End of function rangestringtorangearray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.54 ms | 1015 KiB | 20 Q