3v4l.org

run code in 300+ PHP versions simultaneously
<?php $examples = [ 'The time is over. # its mean I\'m need to die.', 'Please help me. # Ghost. I am here alone.', 'Sorry. # help yourself.']; foreach ($examples as $example) { $exploded = explode('#', $example); $substr = trim(substr($exploded[1], 0, strpos($exploded[1], '.'))); var_dump($substr); } echo "------------------------\n"; //////////////////////////////////////////////////////////////////////////////////////////////////////////// $test = parseString('Sorry. # help yourself.'); function parseString($string) { $exploded = explode('#', $string); $substr = trim(substr($exploded[1], 0, strpos($exploded[1], '.'))); return $substr; } var_dump($test); echo "------------------------\n"; //////////////////////////////////////////////////////////////////////////////////////////////////////////// $stringExample = "The time is over. # its mean I'm need to die. Please help me. # Ghost. I am here alone. Sorry. # help yourself."; $test2 = parseString2($stringExample); function parseString2($string) { $result = []; $array = explode("\n", $string); foreach ($array as $a) { $exploded = explode('#', $a); $substr = trim(substr($exploded[1], 0, strpos($exploded[1], '.'))); $result[] = $substr; } return $result; } var_dump($test2); echo "------------------------\n"; //////////////////////////////////////////////////////////////////////////////////////////////////////////// $stringExample2 = "The time is over. # its mean I'm need to die. Please help me. # Ghost. I am here alone. Sorry. # help yourself."; var_dump(parseString3($stringExample2)); function parseString3($stringExample) { $result2 = []; $startBlock = false; $block = 0; foreach (str_split($stringExample) as $char) { if ($char === '#') { // Start block $startBlock = true; } else if ($startBlock && $char === '.') { // End block $result2[$block] = trim($result2[$block]); // Remove unnecessary whitespace $block++; $startBlock = false; } else if ($startBlock) { // Character to append to block if (!isset($result2[$block])) { $result2[$block] = ''; } $result2[$block] .= $char; } } return $result2; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 27
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 27
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/k3TXM
function name:  (null)
number of ops:  54
compiled vars:  !0 = $examples, !1 = $example, !2 = $exploded, !3 = $substr, !4 = $test, !5 = $stringExample, !6 = $test2, !7 = $stringExample2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    8     1      > FE_RESET_R                                       $9      !0, ->27
          2    > > FE_FETCH_R                                               $9, !1, ->27
    9     3    >   INIT_FCALL                                               'explode'
          4        SEND_VAL                                                 '%23'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $10     
          7        ASSIGN                                                   !2, $10
   10     8        INIT_FCALL                                               'trim'
          9        INIT_FCALL                                               'substr'
         10        FETCH_DIM_R                                      ~12     !2, 1
         11        SEND_VAL                                                 ~12
         12        SEND_VAL                                                 0
         13        INIT_FCALL                                               'strpos'
         14        FETCH_DIM_R                                      ~13     !2, 1
         15        SEND_VAL                                                 ~13
         16        SEND_VAL                                                 '.'
         17        DO_ICALL                                         $14     
         18        SEND_VAR                                                 $14
         19        DO_ICALL                                         $15     
         20        SEND_VAR                                                 $15
         21        DO_ICALL                                         $16     
         22        ASSIGN                                                   !3, $16
   11    23        INIT_FCALL                                               'var_dump'
         24        SEND_VAR                                                 !3
         25        DO_ICALL                                                 
    8    26      > JMP                                                      ->2
         27    >   FE_FREE                                                  $9
   15    28        ECHO                                                     '------------------------%0A'
   17    29        INIT_FCALL_BY_NAME                                       'parseString'
         30        SEND_VAL_EX                                              'Sorry.+%23+help+yourself.'
         31        DO_FCALL                                      0  $19     
         32        ASSIGN                                                   !4, $19
   26    33        INIT_FCALL                                               'var_dump'
         34        SEND_VAR                                                 !4
         35        DO_ICALL                                                 
   27    36        ECHO                                                     '------------------------%0A'
   29    37        ASSIGN                                                   !5, 'The+time+is+over.+%23+its+mean+I%27m+need+to+die.%0APlease+help+me.+%23+Ghost.+I+am+here+alone.%0ASorry.+%23+help+yourself.'
   34    38        INIT_FCALL_BY_NAME                                       'parseString2'
         39        SEND_VAR_EX                                              !5
         40        DO_FCALL                                      0  $23     
         41        ASSIGN                                                   !6, $23
   49    42        INIT_FCALL                                               'var_dump'
         43        SEND_VAR                                                 !6
         44        DO_ICALL                                                 
   50    45        ECHO                                                     '------------------------%0A'
   52    46        ASSIGN                                                   !7, 'The+time+is+over.+%23+its+mean+I%27m+need+to+die.+Please+help+me.+%23+Ghost.+I+am+here+alone.+Sorry.+%23+help+yourself.'
   55    47        INIT_FCALL                                               'var_dump'
         48        INIT_FCALL_BY_NAME                                       'parseString3'
         49        SEND_VAR_EX                                              !7
         50        DO_FCALL                                      0  $27     
         51        SEND_VAR                                                 $27
         52        DO_ICALL                                                 
   79    53      > RETURN                                                   1

Function parsestring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k3TXM
function name:  parseString
number of ops:  23
compiled vars:  !0 = $string, !1 = $exploded, !2 = $substr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   20     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%23'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !1, $3
   21     6        INIT_FCALL                                               'trim'
          7        INIT_FCALL                                               'substr'
          8        FETCH_DIM_R                                      ~5      !1, 1
          9        SEND_VAL                                                 ~5
         10        SEND_VAL                                                 0
         11        INIT_FCALL                                               'strpos'
         12        FETCH_DIM_R                                      ~6      !1, 1
         13        SEND_VAL                                                 ~6
         14        SEND_VAL                                                 '.'
         15        DO_ICALL                                         $7      
         16        SEND_VAR                                                 $7
         17        DO_ICALL                                         $8      
         18        SEND_VAR                                                 $8
         19        DO_ICALL                                         $9      
         20        ASSIGN                                                   !2, $9
   23    21      > RETURN                                                   !2
   24    22*     > RETURN                                                   null

End of function parsestring

Function parsestring2:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 32
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 32
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/k3TXM
function name:  parseString2
number of ops:  35
compiled vars:  !0 = $string, !1 = $result, !2 = $array, !3 = $a, !4 = $exploded, !5 = $substr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   37     1        ASSIGN                                                   !1, <array>
   38     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '%0A'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $7      
          6        ASSIGN                                                   !2, $7
   40     7      > FE_RESET_R                                       $9      !2, ->32
          8    > > FE_FETCH_R                                               $9, !3, ->32
   41     9    >   INIT_FCALL                                               'explode'
         10        SEND_VAL                                                 '%23'
         11        SEND_VAR                                                 !3
         12        DO_ICALL                                         $10     
         13        ASSIGN                                                   !4, $10
   42    14        INIT_FCALL                                               'trim'
         15        INIT_FCALL                                               'substr'
         16        FETCH_DIM_R                                      ~12     !4, 1
         17        SEND_VAL                                                 ~12
         18        SEND_VAL                                                 0
         19        INIT_FCALL                                               'strpos'
         20        FETCH_DIM_R                                      ~13     !4, 1
         21        SEND_VAL                                                 ~13
         22        SEND_VAL                                                 '.'
         23        DO_ICALL                                         $14     
         24        SEND_VAR                                                 $14
         25        DO_ICALL                                         $15     
         26        SEND_VAR                                                 $15
         27        DO_ICALL                                         $16     
         28        ASSIGN                                                   !5, $16
   43    29        ASSIGN_DIM                                               !1
         30        OP_DATA                                                  !5
   40    31      > JMP                                                      ->8
         32    >   FE_FREE                                                  $9
   46    33      > RETURN                                                   !1
   47    34*     > RETURN                                                   null

End of function parsestring2

Function parsestring3:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 35
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 35
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 26
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 34
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 32
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 32
Branch analysis from position: 34
Branch analysis from position: 16
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/k3TXM
function name:  parseString3
number of ops:  38
compiled vars:  !0 = $stringExample, !1 = $result2, !2 = $startBlock, !3 = $block, !4 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
   58     1        ASSIGN                                                   !1, <array>
   60     2        ASSIGN                                                   !2, <false>
   62     3        ASSIGN                                                   !3, 0
   63     4        INIT_FCALL                                               'str_split'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $8      
          7      > FE_RESET_R                                       $9      $8, ->35
          8    > > FE_FETCH_R                                               $9, !4, ->35
   64     9    >   IS_IDENTICAL                                             !4, '%23'
         10      > JMPZ                                                     ~10, ->13
   65    11    >   ASSIGN                                                   !2, <true>
   64    12      > JMP                                                      ->34
   66    13    > > JMPZ_EX                                          ~12     !2, ->16
         14    >   IS_IDENTICAL                                     ~13     !4, '.'
         15        BOOL                                             ~12     ~13
         16    > > JMPZ                                                     ~12, ->26
   67    17    >   INIT_FCALL                                               'trim'
         18        FETCH_DIM_R                                      ~15     !1, !3
         19        SEND_VAL                                                 ~15
         20        DO_ICALL                                         $16     
         21        ASSIGN_DIM                                               !1, !3
         22        OP_DATA                                                  $16
   68    23        PRE_INC                                                  !3
   69    24        ASSIGN                                                   !2, <false>
   66    25      > JMP                                                      ->34
   70    26    > > JMPZ                                                     !2, ->34
   71    27    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~19     !1, !3
         28        BOOL_NOT                                         ~20     ~19
         29      > JMPZ                                                     ~20, ->32
   72    30    >   ASSIGN_DIM                                               !1, !3
         31        OP_DATA                                                  ''
   74    32    >   ASSIGN_DIM_OP                .=               8          !1, !3
         33        OP_DATA                                                  !4
   63    34    > > JMP                                                      ->8
         35    >   FE_FREE                                                  $9
   78    36      > RETURN                                                   !1
   79    37*     > RETURN                                                   null

End of function parsestring3

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
283.71 ms | 1020 KiB | 19 Q