3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isPalindrome(string &$str): bool { $regex = <<<REGEX / ^ #start of string ( #start capture group 1 ( #start capture group 2 . #match any non-newline character ) #end capture group2 (?1) #repeat the expression of capture group 1 \2 #match the character from capture group 2 | #or .? #the middle character (if odd length input string) or no character (if even length input string) ) #end capture group 1 $ #end of string /x REGEX; return (bool) preg_match($regex, $str); } function sanitizePalindrome(&$str) { return preg_replace('/[^a-z]+/', '', strtolower($str)); } $tests = [ '', 'radar', 'f', 'neveroddoreven', 'foo', 'palindrome', 'Red rum, sir, is murder' ]; foreach ($tests as $test) { $test = sanitizePalindrome($test); // this is optional printf("%20s : %s\n", $test, json_encode(isPalindrome($test))); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 19
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 19
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/lOZVQ
function name:  (null)
number of ops:  21
compiled vars:  !0 = $tests, !1 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   ASSIGN                                                   !0, <array>
   37     1      > FE_RESET_R                                       $3      !0, ->19
          2    > > FE_FETCH_R                                               $3, !1, ->19
   38     3    >   INIT_FCALL                                               'sanitizepalindrome'
          4        SEND_REF                                                 !1
          5        DO_FCALL                                      0  $4      
          6        ASSIGN                                                   !1, $4
   39     7        INIT_FCALL                                               'printf'
          8        SEND_VAL                                                 '%2520s+%3A+%25s%0A'
          9        SEND_VAR                                                 !1
         10        INIT_FCALL                                               'json_encode'
         11        INIT_FCALL                                               'ispalindrome'
         12        SEND_REF                                                 !1
         13        DO_FCALL                                      0  $6      
         14        SEND_VAR                                                 $6
         15        DO_ICALL                                         $7      
         16        SEND_VAR                                                 $7
         17        DO_ICALL                                                 
   37    18      > JMP                                                      ->2
         19    >   FE_FREE                                                  $3
   40    20      > RETURN                                                   1

Function ispalindrome:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lOZVQ
function name:  isPalindrome
number of ops:  11
compiled vars:  !0 = $str, !1 = $regex
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, '%2F%0A%5E+++++++%23start+of+string%0A%28+++++++%23start+capture+group+1%0A+%28++++++%23start+capture+group+2+%0A++.+++++%23match+any+non-newline+character%0A+%29++++++%23end+capture+group2%0A+%28%3F1%29+++%23repeat+the+expression+of+capture+group+1%0A+%02+++++%23match+the+character+from+capture+group+2%0A+%7C++++++%23or%0A+.%3F+++++%23the+middle+character+%28if+odd+length+input+string%29+or+no+character+%28if+even+length+input+string%29%0A%29+++++++%23end+capture+group+1%0A%24+++++++%23end+of+string%0A%2Fx'
   20     2        INIT_FCALL                                               'preg_match'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $3      
          6        BOOL                                             ~4      $3
          7        VERIFY_RETURN_TYPE                                       ~4
          8      > RETURN                                                   ~4
   21     9*       VERIFY_RETURN_TYPE                                       
         10*     > RETURN                                                   null

End of function ispalindrome

Function sanitizepalindrome:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lOZVQ
function name:  sanitizePalindrome
number of ops:  11
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   25     1        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 '%2F%5B%5Ea-z%5D%2B%2F'
          3        SEND_VAL                                                 ''
          4        INIT_FCALL                                               'strtolower'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $1      
          7        SEND_VAR                                                 $1
          8        DO_ICALL                                         $2      
          9      > RETURN                                                   $2
   26    10*     > RETURN                                                   null

End of function sanitizepalindrome

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
190.75 ms | 1022 KiB | 20 Q