3v4l.org

run code in 500+ 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 = 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/k3TXM
function name:  (null)
number of ops:  46
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, ->19
          2    > > FE_FETCH_R                                                   $9, !1, ->19
    9     3    >   INIT_FCALL                                                   'explode'
          4        SEND_VAL                                                     '%23'
          5        SEND_VAR                                                     !1
          6        DO_ICALL                                             $10     
          7        ASSIGN                                                       !2, $10
   10     8        FETCH_DIM_R                                          ~12     !2, 1
          9        FETCH_DIM_R                                          ~13     !2, 1
         10        FRAMELESS_ICALL_2                strpos              ~14     ~13, '.'
         11        FRAMELESS_ICALL_3                substr              ~15     ~12, 0
         12        OP_DATA                                                      ~14
         13        FRAMELESS_ICALL_1                trim                ~16     ~15
         14        ASSIGN                                                       !3, ~16
   11    15        INIT_FCALL                                                   'var_dump'
         16        SEND_VAR                                                     !3
         17        DO_ICALL                                                     
    8    18      > JMP                                                          ->2
         19    >   FE_FREE                                                      $9
   15    20        ECHO                                                         '------------------------%0A'
   17    21        INIT_FCALL_BY_NAME                                           'parseString'
         22        SEND_VAL_EX                                                  'Sorry.+%23+help+yourself.'
         23        DO_FCALL                                          0  $19     
         24        ASSIGN                                                       !4, $19
   26    25        INIT_FCALL                                                   'var_dump'
         26        SEND_VAR                                                     !4
         27        DO_ICALL                                                     
   27    28        ECHO                                                         '------------------------%0A'
   29    29        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    30        INIT_FCALL_BY_NAME                                           'parseString2'
         31        SEND_VAR_EX                                                  !5
         32        DO_FCALL                                          0  $23     
         33        ASSIGN                                                       !6, $23
   49    34        INIT_FCALL                                                   'var_dump'
         35        SEND_VAR                                                     !6
         36        DO_ICALL                                                     
   50    37        ECHO                                                         '------------------------%0A'
   52    38        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    39        INIT_FCALL                                                   'var_dump'
         40        INIT_FCALL_BY_NAME                                           'parseString3'
         41        SEND_VAR_EX                                                  !7
         42        DO_FCALL                                          0  $27     
         43        SEND_VAR                                                     $27
         44        DO_ICALL                                                     
   79    45      > 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:  15
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        FETCH_DIM_R                                          ~5      !1, 1
          7        FETCH_DIM_R                                          ~6      !1, 1
          8        FRAMELESS_ICALL_2                strpos              ~7      ~6, '.'
          9        FRAMELESS_ICALL_3                substr              ~8      ~5, 0
         10        OP_DATA                                                      ~7
         11        FRAMELESS_ICALL_1                trim                ~9      ~8
         12        ASSIGN                                                       !2, ~9
   23    13      > RETURN                                                       !2
   24    14*     > 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 = 24
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 24
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/k3TXM
function name:  parseString2
number of ops:  27
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, ->24
          8    > > FE_FETCH_R                                                   $9, !3, ->24
   41     9    >   INIT_FCALL                                                   'explode'
         10        SEND_VAL                                                     '%23'
         11        SEND_VAR                                                     !3
         12        DO_ICALL                                             $10     
         13        ASSIGN                                                       !4, $10
   42    14        FETCH_DIM_R                                          ~12     !4, 1
         15        FETCH_DIM_R                                          ~13     !4, 1
         16        FRAMELESS_ICALL_2                strpos              ~14     ~13, '.'
         17        FRAMELESS_ICALL_3                substr              ~15     ~12, 0
         18        OP_DATA                                                      ~14
         19        FRAMELESS_ICALL_1                trim                ~16     ~15
         20        ASSIGN                                                       !5, ~16
   43    21        ASSIGN_DIM                                                   !1
         22        OP_DATA                                                      !5
   40    23      > JMP                                                          ->8
         24    >   FE_FREE                                                      $9
   46    25      > RETURN                                                       !1
   47    26*     > 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 = 33
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 33
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 = 32
Branch analysis from position: 32
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 = 24
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 32
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 30
Branch analysis from position: 32
Branch analysis from position: 16
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/k3TXM
function name:  parseString3
number of ops:  36
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, ->33
          8    > > FE_FETCH_R                                                   $9, !4, ->33
   64     9    >   IS_IDENTICAL                                                 !4, '%23'
         10      > JMPZ                                                         ~10, ->13
   65    11    >   ASSIGN                                                       !2, <true>
   64    12      > JMP                                                          ->32
   66    13    > > JMPZ_EX                                              ~12     !2, ->16
         14    >   IS_IDENTICAL                                         ~13     !4, '.'
         15        BOOL                                                 ~12     ~13
         16    > > JMPZ                                                         ~12, ->24
   67    17    >   FETCH_DIM_R                                          ~15     !1, !3
         18        FRAMELESS_ICALL_1                trim                ~16     ~15
         19        ASSIGN_DIM                                                   !1, !3
         20        OP_DATA                                                      ~16
   68    21        PRE_INC                                                      !3
   69    22        ASSIGN                                                       !2, <false>
   66    23      > JMP                                                          ->32
   70    24    > > JMPZ                                                         !2, ->32
   71    25    >   ISSET_ISEMPTY_DIM_OBJ                             0  ~19     !1, !3
         26        BOOL_NOT                                             ~20     ~19
         27      > JMPZ                                                         ~20, ->30
   72    28    >   ASSIGN_DIM                                                   !1, !3
         29        OP_DATA                                                      ''
   74    30    >   ASSIGN_DIM_OP                    .=               8          !1, !3
         31        OP_DATA                                                      !4
   63    32    > > JMP                                                          ->8
         33    >   FE_FREE                                                      $9
   78    34      > RETURN                                                       !1
   79    35*     > RETURN                                                       null

End of function parsestring3

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
169.73 ms | 2721 KiB | 21 Q