3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getFormattedString($str) { return implode('', explode(' ', mb_strtolower($str, 'UTF-8'))); } function getOddLengthPalindromeArray($str) { $result = []; $l = 0; $r = -1; for ($i = 0, $n = mb_strlen($str, 'UTF-8'); $i < $n; $i++) { $k = ($i > $r ? 1 : min($result[$l + $r - $i], $r - $i)); echo $str[$i - $k]; while ($i - $k >= 0 && $i + $k < $n && $str[$i - $k] == $str[$i + $k]) { $k++; } $result[$i] = $k; if ($i + $k - 1 > $r) { $l = $i - $k + 1; $r = $i + $k - 1; } } return $result; } function getEvenLengthPalindromeArray($str) { $result = []; $l = 0; $r = -1; for ($i = 0, $n = mb_strlen($str, 'UTF-8'); $i < $n; $i++) { $k = ($i > $r ? 0 : min($result[$l + $r - $i - 1], $r - $i)); while ($i - $k >= 0 && $i + $k + 1 < $n && $str[$i - $k] == $str[$i + $k + 1]) { $k++; } $result[$i] = $k; if ($i + $k > $r) { $l = $i - $k + 1; $r = $i + $k; } } return $result; } $formattedString = getFormattedString("Аргентина манит негра"); $oddPalindromeArray = getOddLengthPalindromeArray($formattedString); $evenPalindromeArray = getEvenLengthPalindromeArray($formattedString); $maxOddValue = max($oddPalindromeArray); $maxEvenValue = max($evenPalindromeArray); $maxOddPalindromeLength = $maxOddValue * 2 - 1; $maxEvenPalindromeLength = $maxEvenValue * 2; if ($maxOddPalindromeLength > $maxEvenPalindromeLength && $maxOddValue !== 1) { $maxOddKey = array_search($maxOddValue, $oddPalindromeArray); var_dump($oddPalindromeArray); //var_dump(mb_substr($formattedString, $maxOddKey - $maxOddValue + 1, $maxOddPalindromeLength, 'UTF-8')); } elseif ($maxOddValue * 2 - 1 < $maxEvenValue * 2 && $maxEvenValue !== 0) { $maxEvenKey = array_search($maxEvenValue, $evenPalindromeArray); var_dump(mb_substr($formattedString, $maxEvenKey - $maxEvenValue, $maxEvenPalindromeLength, 'UTF-8')); } else { var_dump($formattedString[0]); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 27, Position 2 = 29
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 39
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
2 jumps found. (Code = 46) Position 1 = 44, Position 2 = 46
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 63
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
Branch analysis from position: 29
filename:       /in/R1Hd0
function name:  (null)
number of ops:  68
compiled vars:  !0 = $formattedString, !1 = $oddPalindromeArray, !2 = $evenPalindromeArray, !3 = $maxOddValue, !4 = $maxEvenValue, !5 = $maxOddPalindromeLength, !6 = $maxEvenPalindromeLength, !7 = $maxOddKey, !8 = $maxEvenKey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   INIT_FCALL                                               'getformattedstring'
          1        SEND_VAL                                                 '%D0%90%D1%80%D0%B3%D0%B5%D0%BD%D1%82%D0%B8%D0%BD%D0%B0+%D0%BC%D0%B0%D0%BD%D0%B8%D1%82+%D0%BD%D0%B5%D0%B3%D1%80%D0%B0'
          2        DO_FCALL                                      0  $9      
          3        ASSIGN                                                   !0, $9
   51     4        INIT_FCALL                                               'getoddlengthpalindromearray'
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $11     
          7        ASSIGN                                                   !1, $11
   52     8        INIT_FCALL                                               'getevenlengthpalindromearray'
          9        SEND_VAR                                                 !0
         10        DO_FCALL                                      0  $13     
         11        ASSIGN                                                   !2, $13
   54    12        INIT_FCALL                                               'max'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $15     
         15        ASSIGN                                                   !3, $15
   55    16        INIT_FCALL                                               'max'
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                         $17     
         19        ASSIGN                                                   !4, $17
   56    20        MUL                                              ~19     !3, 2
         21        SUB                                              ~20     ~19, 1
         22        ASSIGN                                                   !5, ~20
   57    23        MUL                                              ~22     !4, 2
         24        ASSIGN                                                   !6, ~22
   59    25        IS_SMALLER                                       ~24     !6, !5
         26      > JMPZ_EX                                          ~24     ~24, ->29
         27    >   IS_NOT_IDENTICAL                                 ~25     !3, 1
         28        BOOL                                             ~24     ~25
         29    > > JMPZ                                                     ~24, ->39
   60    30    >   INIT_FCALL                                               'array_search'
         31        SEND_VAR                                                 !3
         32        SEND_VAR                                                 !1
         33        DO_ICALL                                         $26     
         34        ASSIGN                                                   !7, $26
   61    35        INIT_FCALL                                               'var_dump'
         36        SEND_VAR                                                 !1
         37        DO_ICALL                                                 
         38      > JMP                                                      ->67
   63    39    >   MUL                                              ~29     !3, 2
         40        SUB                                              ~30     ~29, 1
         41        MUL                                              ~31     !4, 2
         42        IS_SMALLER                                       ~32     ~30, ~31
         43      > JMPZ_EX                                          ~32     ~32, ->46
         44    >   IS_NOT_IDENTICAL                                 ~33     !4, 0
         45        BOOL                                             ~32     ~33
         46    > > JMPZ                                                     ~32, ->63
   64    47    >   INIT_FCALL                                               'array_search'
         48        SEND_VAR                                                 !4
         49        SEND_VAR                                                 !2
         50        DO_ICALL                                         $34     
         51        ASSIGN                                                   !8, $34
   65    52        INIT_FCALL                                               'var_dump'
         53        INIT_FCALL                                               'mb_substr'
         54        SEND_VAR                                                 !0
         55        SUB                                              ~36     !8, !4
         56        SEND_VAL                                                 ~36
         57        SEND_VAR                                                 !6
         58        SEND_VAL                                                 'UTF-8'
         59        DO_ICALL                                         $37     
         60        SEND_VAR                                                 $37
         61        DO_ICALL                                                 
         62      > JMP                                                      ->67
   67    63    >   INIT_FCALL                                               'var_dump'
         64        FETCH_DIM_R                                      ~39     !0, 0
         65        SEND_VAL                                                 ~39
         66        DO_ICALL                                                 
   68    67    > > RETURN                                                   1

Function getformattedstring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R1Hd0
function name:  getFormattedString
number of ops:  15
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'implode'
          2        SEND_VAL                                                 ''
          3        INIT_FCALL                                               'explode'
          4        SEND_VAL                                                 '+'
          5        INIT_FCALL                                               'mb_strtolower'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 'UTF-8'
          8        DO_ICALL                                         $1      
          9        SEND_VAR                                                 $1
         10        DO_ICALL                                         $2      
         11        SEND_VAR                                                 $2
         12        DO_ICALL                                         $3      
         13      > RETURN                                                   $3
    5    14*     > RETURN                                                   null

End of function getformattedstring

Function getoddlengthpalindromearray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 11
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 46) Position 1 = 33, Position 2 = 36
Branch analysis from position: 33
2 jumps found. (Code = 46) Position 1 = 37, Position 2 = 43
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 29
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 56
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 11
Branch analysis from position: 59
Branch analysis from position: 11
Branch analysis from position: 56
Branch analysis from position: 29
2 jumps found. (Code = 46) Position 1 = 33, Position 2 = 36
Branch analysis from position: 33
Branch analysis from position: 36
Branch analysis from position: 43
Branch analysis from position: 36
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
filename:       /in/R1Hd0
function name:  getOddLengthPalindromeArray
number of ops:  61
compiled vars:  !0 = $str, !1 = $result, !2 = $l, !3 = $r, !4 = $i, !5 = $n, !6 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    9     1        ASSIGN                                                   !1, <array>
   10     2        ASSIGN                                                   !2, 0
   11     3        ASSIGN                                                   !3, -1
   13     4        ASSIGN                                                   !4, 0
          5        INIT_FCALL                                               'mb_strlen'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 'UTF-8'
          8        DO_ICALL                                         $11     
          9        ASSIGN                                                   !5, $11
         10      > JMP                                                      ->57
   14    11    >   IS_SMALLER                                               !3, !4
         12      > JMPZ                                                     ~13, ->15
         13    >   QM_ASSIGN                                        ~14     1
         14      > JMP                                                      ->24
         15    >   INIT_FCALL                                               'min'
         16        ADD                                              ~15     !2, !3
         17        SUB                                              ~16     ~15, !4
         18        FETCH_DIM_R                                      ~17     !1, ~16
         19        SEND_VAL                                                 ~17
         20        SUB                                              ~18     !3, !4
         21        SEND_VAL                                                 ~18
         22        DO_ICALL                                         $19     
         23        QM_ASSIGN                                        ~14     $19
         24    >   ASSIGN                                                   !6, ~14
   15    25        SUB                                              ~21     !4, !6
         26        FETCH_DIM_R                                      ~22     !0, ~21
         27        ECHO                                                     ~22
   16    28      > JMP                                                      ->30
   17    29    >   PRE_INC                                                  !6
   16    30    >   SUB                                              ~24     !4, !6
         31        IS_SMALLER_OR_EQUAL                              ~25     0, ~24
         32      > JMPZ_EX                                          ~25     ~25, ->36
         33    >   ADD                                              ~26     !4, !6
         34        IS_SMALLER                                       ~27     ~26, !5
         35        BOOL                                             ~25     ~27
         36    > > JMPZ_EX                                          ~25     ~25, ->43
         37    >   SUB                                              ~28     !4, !6
         38        FETCH_DIM_R                                      ~29     !0, ~28
         39        ADD                                              ~30     !4, !6
         40        FETCH_DIM_R                                      ~31     !0, ~30
         41        IS_EQUAL                                         ~32     ~29, ~31
         42        BOOL                                             ~25     ~32
         43    > > JMPNZ                                                    ~25, ->29
   19    44    >   ASSIGN_DIM                                               !1, !4
         45        OP_DATA                                                  !6
   20    46        ADD                                              ~34     !4, !6
         47        SUB                                              ~35     ~34, 1
         48        IS_SMALLER                                               !3, ~35
         49      > JMPZ                                                     ~36, ->56
   21    50    >   SUB                                              ~37     !4, !6
         51        ADD                                              ~38     ~37, 1
         52        ASSIGN                                                   !2, ~38
   22    53        ADD                                              ~40     !4, !6
         54        SUB                                              ~41     ~40, 1
         55        ASSIGN                                                   !3, ~41
   13    56    >   PRE_INC                                                  !4
         57    >   IS_SMALLER                                               !4, !5
         58      > JMPNZ                                                    ~44, ->11
   26    59    > > RETURN                                                   !1
   27    60*     > RETURN                                                   null

End of function getoddlengthpalindromearray

Function getevenlengthpalindromearray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 11
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 46) Position 1 = 31, Position 2 = 35
Branch analysis from position: 31
2 jumps found. (Code = 46) Position 1 = 36, Position 2 = 43
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 27
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 54
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 11
Branch analysis from position: 57
Branch analysis from position: 11
Branch analysis from position: 54
Branch analysis from position: 27
2 jumps found. (Code = 46) Position 1 = 31, Position 2 = 35
Branch analysis from position: 31
Branch analysis from position: 35
Branch analysis from position: 43
Branch analysis from position: 35
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
filename:       /in/R1Hd0
function name:  getEvenLengthPalindromeArray
number of ops:  59
compiled vars:  !0 = $str, !1 = $result, !2 = $l, !3 = $r, !4 = $i, !5 = $n, !6 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   31     1        ASSIGN                                                   !1, <array>
   32     2        ASSIGN                                                   !2, 0
   33     3        ASSIGN                                                   !3, -1
   35     4        ASSIGN                                                   !4, 0
          5        INIT_FCALL                                               'mb_strlen'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 'UTF-8'
          8        DO_ICALL                                         $11     
          9        ASSIGN                                                   !5, $11
         10      > JMP                                                      ->55
   36    11    >   IS_SMALLER                                               !3, !4
         12      > JMPZ                                                     ~13, ->15
         13    >   QM_ASSIGN                                        ~14     0
         14      > JMP                                                      ->25
         15    >   INIT_FCALL                                               'min'
         16        ADD                                              ~15     !2, !3
         17        SUB                                              ~16     ~15, !4
         18        SUB                                              ~17     ~16, 1
         19        FETCH_DIM_R                                      ~18     !1, ~17
         20        SEND_VAL                                                 ~18
         21        SUB                                              ~19     !3, !4
         22        SEND_VAL                                                 ~19
         23        DO_ICALL                                         $20     
         24        QM_ASSIGN                                        ~14     $20
         25    >   ASSIGN                                                   !6, ~14
   37    26      > JMP                                                      ->28
   38    27    >   PRE_INC                                                  !6
   37    28    >   SUB                                              ~23     !4, !6
         29        IS_SMALLER_OR_EQUAL                              ~24     0, ~23
         30      > JMPZ_EX                                          ~24     ~24, ->35
         31    >   ADD                                              ~25     !4, !6
         32        ADD                                              ~26     ~25, 1
         33        IS_SMALLER                                       ~27     ~26, !5
         34        BOOL                                             ~24     ~27
         35    > > JMPZ_EX                                          ~24     ~24, ->43
         36    >   SUB                                              ~28     !4, !6
         37        FETCH_DIM_R                                      ~29     !0, ~28
         38        ADD                                              ~30     !4, !6
         39        ADD                                              ~31     ~30, 1
         40        FETCH_DIM_R                                      ~32     !0, ~31
         41        IS_EQUAL                                         ~33     ~29, ~32
         42        BOOL                                             ~24     ~33
         43    > > JMPNZ                                                    ~24, ->27
   40    44    >   ASSIGN_DIM                                               !1, !4
         45        OP_DATA                                                  !6
   41    46        ADD                                              ~35     !4, !6
         47        IS_SMALLER                                               !3, ~35
         48      > JMPZ                                                     ~36, ->54
   42    49    >   SUB                                              ~37     !4, !6
         50        ADD                                              ~38     ~37, 1
         51        ASSIGN                                                   !2, ~38
   43    52        ADD                                              ~40     !4, !6
         53        ASSIGN                                                   !3, ~40
   35    54    >   PRE_INC                                                  !4
         55    >   IS_SMALLER                                               !4, !5
         56      > JMPNZ                                                    ~43, ->11
   47    57    > > RETURN                                                   !1
   48    58*     > RETURN                                                   null

End of function getevenlengthpalindromearray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.95 ms | 1418 KiB | 34 Q