3v4l.org

run code in 300+ PHP versions simultaneously
<?php // old and new strings $old = "Foo \r\nFoo\r\nBar\r\nQux"; $new = "Foo\nBar\nBaz"; // convert all line endings to the same type $old = str_replace(["\r\n", "\r"], "\n", $old); $new = str_replace(["\r\n", "\r"], "\n", $new); // seperate into lines $old_lines = explode("\n", $old); $new_lines = explode("\n", $new); // optional: remove whitespace so spaces don't trigger falsely array_walk($old_lines, function(&$value) { $value = rtrim($value); }); array_walk($new_lines, function(&$value) { $value = rtrim($value); }); // figure out which one is longer if (count($old_lines) >= count($new_lines)) { $primary = $old_lines; $secondary = $new_lines; } else { $primary = $new_lines; $secondary = $old_lines; } // compare line by line $results = []; foreach ($primary as $key => $value) { if (key_exists($key, $secondary)) { if ($primary[$key] == $secondary[$key]) { $results[] = "MATCH"; } else { $results[] = "DIFFERENT"; } } else { $results[] = "MISSING"; } } var_dump($old_lines); var_dump($new_lines); var_dump($results);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 41
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
2 jumps found. (Code = 77) Position 1 = 45, Position 2 = 65
Branch analysis from position: 45
2 jumps found. (Code = 78) Position 1 = 46, Position 2 = 65
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 62
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 59
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 64
Branch analysis from position: 64
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 65
Branch analysis from position: 41
2 jumps found. (Code = 77) Position 1 = 45, Position 2 = 65
Branch analysis from position: 45
Branch analysis from position: 65
filename:       /in/gcd13
function name:  (null)
number of ops:  76
compiled vars:  !0 = $old, !1 = $new, !2 = $old_lines, !3 = $new_lines, !4 = $primary, !5 = $secondary, !6 = $results, !7 = $value, !8 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, 'Foo+%0D%0AFoo%0D%0ABar%0D%0AQux'
    5     1        ASSIGN                                                   !1, 'Foo%0ABar%0ABaz'
    8     2        INIT_FCALL                                               'str_replace'
          3        SEND_VAL                                                 <array>
          4        SEND_VAL                                                 '%0A'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $11     
          7        ASSIGN                                                   !0, $11
    9     8        INIT_FCALL                                               'str_replace'
          9        SEND_VAL                                                 <array>
         10        SEND_VAL                                                 '%0A'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $13     
         13        ASSIGN                                                   !1, $13
   12    14        INIT_FCALL                                               'explode'
         15        SEND_VAL                                                 '%0A'
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                         $15     
         18        ASSIGN                                                   !2, $15
   13    19        INIT_FCALL                                               'explode'
         20        SEND_VAL                                                 '%0A'
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                         $17     
         23        ASSIGN                                                   !3, $17
   16    24        INIT_FCALL                                               'array_walk'
         25        SEND_REF                                                 !2
         26        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fgcd13%3A16%240'
   18    27        SEND_VAL                                                 ~19
         28        DO_ICALL                                                 
   19    29        INIT_FCALL                                               'array_walk'
         30        SEND_REF                                                 !3
         31        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fgcd13%3A19%241'
   21    32        SEND_VAL                                                 ~21
         33        DO_ICALL                                                 
   24    34        COUNT                                            ~23     !2
         35        COUNT                                            ~24     !3
         36        IS_SMALLER_OR_EQUAL                                      ~24, ~23
         37      > JMPZ                                                     ~25, ->41
   25    38    >   ASSIGN                                                   !4, !2
   26    39        ASSIGN                                                   !5, !3
         40      > JMP                                                      ->43
   28    41    >   ASSIGN                                                   !4, !3
   29    42        ASSIGN                                                   !5, !2
   33    43    >   ASSIGN                                                   !6, <array>
   34    44      > FE_RESET_R                                       $31     !4, ->65
         45    > > FE_FETCH_R                                       ~32     $31, !7, ->65
         46    >   ASSIGN                                                   !8, ~32
   35    47        INIT_FCALL                                               'key_exists'
         48        SEND_VAR                                                 !8
         49        SEND_VAR                                                 !5
         50        DO_ICALL                                         $34     
         51      > JMPZ                                                     $34, ->62
   36    52    >   FETCH_DIM_R                                      ~35     !4, !8
         53        FETCH_DIM_R                                      ~36     !5, !8
         54        IS_EQUAL                                                 ~35, ~36
         55      > JMPZ                                                     ~37, ->59
   37    56    >   ASSIGN_DIM                                               !6
         57        OP_DATA                                                  'MATCH'
         58      > JMP                                                      ->61
   39    59    >   ASSIGN_DIM                                               !6
         60        OP_DATA                                                  'DIFFERENT'
         61    > > JMP                                                      ->64
   42    62    >   ASSIGN_DIM                                               !6
         63        OP_DATA                                                  'MISSING'
   34    64    > > JMP                                                      ->45
         65    >   FE_FREE                                                  $31
   46    66        INIT_FCALL                                               'var_dump'
         67        SEND_VAR                                                 !2
         68        DO_ICALL                                                 
   47    69        INIT_FCALL                                               'var_dump'
         70        SEND_VAR                                                 !3
         71        DO_ICALL                                                 
   48    72        INIT_FCALL                                               'var_dump'
         73        SEND_VAR                                                 !6
         74        DO_ICALL                                                 
         75      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Fgcd13%3A16%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gcd13
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        INIT_FCALL                                               'rtrim'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4        ASSIGN                                                   !0, $1
   18     5      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fgcd13%3A16%240

Function %00%7Bclosure%7D%2Fin%2Fgcd13%3A19%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gcd13
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        INIT_FCALL                                               'rtrim'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4        ASSIGN                                                   !0, $1
   21     5      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fgcd13%3A19%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.96 ms | 1404 KiB | 25 Q