3v4l.org

run code in 300+ PHP versions simultaneously
<?php function split_preg($str) { return preg_split('//u', $str, -1); } function getFormattedString($str) { return implode('', explode(' ', mb_strtolower($str, 'UTF-8'))); } function getOddLengthPalindromeArray($str) { $result = []; $l = 0; $r = -1; var_dump(array_filter(split_preg($str))); 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/4HkWs
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
-------------------------------------------------------------------------------------
   56     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
   57     4        INIT_FCALL                                               'getoddlengthpalindromearray'
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $11     
          7        ASSIGN                                                   !1, $11
   58     8        INIT_FCALL                                               'getevenlengthpalindromearray'
          9        SEND_VAR                                                 !0
         10        DO_FCALL                                      0  $13     
         11        ASSIGN                                                   !2, $13
   60    12        INIT_FCALL                                               'max'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $15     
         15        ASSIGN                                                   !3, $15
   61    16        INIT_FCALL                                               'max'
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                         $17     
         19        ASSIGN                                                   !4, $17
   62    20        MUL                                              ~19     !3, 2
         21        SUB                                              ~20     ~19, 1
         22        ASSIGN                                                   !5, ~20
   63    23        MUL                                              ~22     !4, 2
         24        ASSIGN                                                   !6, ~22
   65    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
   66    30    >   INIT_FCALL                                               'array_search'
         31        SEND_VAR                                                 !3
         32        SEND_VAR                                                 !1
         33        DO_ICALL                                         $26     
         34        ASSIGN                                                   !7, $26
   67    35        INIT_FCALL                                               'var_dump'
         36        SEND_VAR                                                 !1
         37        DO_ICALL                                                 
         38      > JMP                                                      ->67
   69    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
   70    47    >   INIT_FCALL                                               'array_search'
         48        SEND_VAR                                                 !4
         49        SEND_VAR                                                 !2
         50        DO_ICALL                                         $34     
         51        ASSIGN                                                   !8, $34
   71    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
   73    63    >   INIT_FCALL                                               'var_dump'
         64        FETCH_DIM_R                                      ~39     !0, 0
         65        SEND_VAL                                                 ~39
         66        DO_ICALL                                                 
   74    67    > > RETURN                                                   1

Function split_preg:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4HkWs
function name:  split_preg
number of ops:  8
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'preg_split'
          2        SEND_VAL                                                 '%2F%2Fu'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 -1
          5        DO_ICALL                                         $1      
          6      > RETURN                                                   $1
    5     7*     > RETURN                                                   null

End of function split_preg

Function getformattedstring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4HkWs
function name:  getFormattedString
number of ops:  15
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     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
    9    14*     > RETURN                                                   null

End of function getformattedstring

Function getoddlengthpalindromearray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 66
Branch analysis from position: 66
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 20
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 46) Position 1 = 42, Position 2 = 45
Branch analysis from position: 42
2 jumps found. (Code = 46) Position 1 = 46, Position 2 = 52
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 38
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 65
Branch analysis from position: 59
2 jumps found. (Code = 44) Position 1 = 68, Position 2 = 20
Branch analysis from position: 68
Branch analysis from position: 20
Branch analysis from position: 65
Branch analysis from position: 38
2 jumps found. (Code = 46) Position 1 = 42, Position 2 = 45
Branch analysis from position: 42
Branch analysis from position: 45
Branch analysis from position: 52
Branch analysis from position: 45
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
filename:       /in/4HkWs
function name:  getOddLengthPalindromeArray
number of ops:  70
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
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
   13     1        ASSIGN                                                   !1, <array>
   14     2        ASSIGN                                                   !2, 0
   15     3        ASSIGN                                                   !3, -1
   17     4        INIT_FCALL                                               'var_dump'
          5        INIT_FCALL                                               'array_filter'
          6        INIT_FCALL                                               'split_preg'
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0  $10     
          9        SEND_VAR                                                 $10
         10        DO_ICALL                                         $11     
         11        SEND_VAR                                                 $11
         12        DO_ICALL                                                 
   19    13        ASSIGN                                                   !4, 0
         14        INIT_FCALL                                               'mb_strlen'
         15        SEND_VAR                                                 !0
         16        SEND_VAL                                                 'UTF-8'
         17        DO_ICALL                                         $14     
         18        ASSIGN                                                   !5, $14
         19      > JMP                                                      ->66
   20    20    >   IS_SMALLER                                               !3, !4
         21      > JMPZ                                                     ~16, ->24
         22    >   QM_ASSIGN                                        ~17     1
         23      > JMP                                                      ->33
         24    >   INIT_FCALL                                               'min'
         25        ADD                                              ~18     !2, !3
         26        SUB                                              ~19     ~18, !4
         27        FETCH_DIM_R                                      ~20     !1, ~19
         28        SEND_VAL                                                 ~20
         29        SUB                                              ~21     !3, !4
         30        SEND_VAL                                                 ~21
         31        DO_ICALL                                         $22     
         32        QM_ASSIGN                                        ~17     $22
         33    >   ASSIGN                                                   !6, ~17
   21    34        SUB                                              ~24     !4, !6
         35        FETCH_DIM_R                                      ~25     !0, ~24
         36        ECHO                                                     ~25
   22    37      > JMP                                                      ->39
   23    38    >   PRE_INC                                                  !6
   22    39    >   SUB                                              ~27     !4, !6
         40        IS_SMALLER_OR_EQUAL                              ~28     0, ~27
         41      > JMPZ_EX                                          ~28     ~28, ->45
         42    >   ADD                                              ~29     !4, !6
         43        IS_SMALLER                                       ~30     ~29, !5
         44        BOOL                                             ~28     ~30
         45    > > JMPZ_EX                                          ~28     ~28, ->52
         46    >   SUB                                              ~31     !4, !6
         47        FETCH_DIM_R                                      ~32     !0, ~31
         48        ADD                                              ~33     !4, !6
         49        FETCH_DIM_R                                      ~34     !0, ~33
         50        IS_EQUAL                                         ~35     ~32, ~34
         51        BOOL                                             ~28     ~35
         52    > > JMPNZ                                                    ~28, ->38
   25    53    >   ASSIGN_DIM                                               !1, !4
         54        OP_DATA                                                  !6
   26    55        ADD                                              ~37     !4, !6
         56        SUB                                              ~38     ~37, 1
         57        IS_SMALLER                                               !3, ~38
         58      > JMPZ                                                     ~39, ->65
   27    59    >   SUB                                              ~40     !4, !6
         60        ADD                                              ~41     ~40, 1
         61        ASSIGN                                                   !2, ~41
   28    62        ADD                                              ~43     !4, !6
         63        SUB                                              ~44     ~43, 1
         64        ASSIGN                                                   !3, ~44
   19    65    >   PRE_INC                                                  !4
         66    >   IS_SMALLER                                               !4, !5
         67      > JMPNZ                                                    ~47, ->20
   32    68    > > RETURN                                                   !1
   33    69*     > 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/4HkWs
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
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   37     1        ASSIGN                                                   !1, <array>
   38     2        ASSIGN                                                   !2, 0
   39     3        ASSIGN                                                   !3, -1
   41     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
   42    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
   43    26      > JMP                                                      ->28
   44    27    >   PRE_INC                                                  !6
   43    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
   46    44    >   ASSIGN_DIM                                               !1, !4
         45        OP_DATA                                                  !6
   47    46        ADD                                              ~35     !4, !6
         47        IS_SMALLER                                               !3, ~35
         48      > JMPZ                                                     ~36, ->54
   48    49    >   SUB                                              ~37     !4, !6
         50        ADD                                              ~38     ~37, 1
         51        ASSIGN                                                   !2, ~38
   49    52        ADD                                              ~40     !4, !6
         53        ASSIGN                                                   !3, ~40
   41    54    >   PRE_INC                                                  !4
         55    >   IS_SMALLER                                               !4, !5
         56      > JMPNZ                                                    ~43, ->11
   53    57    > > RETURN                                                   !1
   54    58*     > RETURN                                                   null

End of function getevenlengthpalindromearray

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
275.41 ms | 1410 KiB | 40 Q