3v4l.org

run code in 300+ PHP versions simultaneously
<?php //$text = file_get_contents('yourfile.txt'); $text = ' 1} ABC Answer: More Words *NEXT* 1} DEF Answer: More Stuff '; //Split each question/answer by the *NEXT* separator $parts = explode('*NEXT*', $text); $result = []; foreach ($parts as $part){ //Split the question and aswer by the Answer: separator list($q, $a) = explode('Answer:', $part, 2); //Remove the #} from the question $q = preg_replace('/^\s*\d+}/', '', $q); //Trim whitespace $q = trim($q); $a = trim($a); $result[$q] = $a; } var_dump($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 36
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 36
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/i5Gi6
function name:  (null)
number of ops:  41
compiled vars:  !0 = $text, !1 = $parts, !2 = $result, !3 = $part, !4 = $q, !5 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, '%0A1%7D+ABC%0A%0A%0A%0AAnswer%3A+More+Words%0A%0A%0A%0A%2ANEXT%2A%0A%0A%0A%0A1%7D+DEF%0A%0A%0A%0AAnswer%3A+More+Stuff%0A'
   25     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%2ANEXT%2A'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $7      
          5        ASSIGN                                                   !1, $7
   27     6        ASSIGN                                                   !2, <array>
   28     7      > FE_RESET_R                                       $10     !1, ->36
          8    > > FE_FETCH_R                                               $10, !3, ->36
   30     9    >   INIT_FCALL                                               'explode'
         10        SEND_VAL                                                 'Answer%3A'
         11        SEND_VAR                                                 !3
         12        SEND_VAL                                                 2
         13        DO_ICALL                                         $11     
         14        FETCH_LIST_R                                     $12     $11, 0
         15        ASSIGN                                                   !4, $12
         16        FETCH_LIST_R                                     $14     $11, 1
         17        ASSIGN                                                   !5, $14
         18        FREE                                                     $11
   33    19        INIT_FCALL                                               'preg_replace'
         20        SEND_VAL                                                 '%2F%5E%5Cs%2A%5Cd%2B%7D%2F'
         21        SEND_VAL                                                 ''
         22        SEND_VAR                                                 !4
         23        DO_ICALL                                         $16     
         24        ASSIGN                                                   !4, $16
   36    25        INIT_FCALL                                               'trim'
         26        SEND_VAR                                                 !4
         27        DO_ICALL                                         $18     
         28        ASSIGN                                                   !4, $18
   37    29        INIT_FCALL                                               'trim'
         30        SEND_VAR                                                 !5
         31        DO_ICALL                                         $20     
         32        ASSIGN                                                   !5, $20
   39    33        ASSIGN_DIM                                               !2, !4
         34        OP_DATA                                                  !5
   28    35      > JMP                                                      ->8
         36    >   FE_FREE                                                  $10
   42    37        INIT_FCALL                                               'var_dump'
         38        SEND_VAR                                                 !2
         39        DO_ICALL                                                 
         40      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
280.43 ms | 1018 KiB | 17 Q