3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = [ "123_String" => "String", "233718_This_is_a_string" => "This_is_a_string", "83_Another Example" => "Another Example", ]; function viaExplode($string) { return explode('_', $string, 2)[1]; // the limit parameter gives reliability } function viaLtrim($string) { return ltrim($string, '0..9_'); // because character after first underscore is not a digit or underscore } function viaPregMatch($string) { return preg_match('/\d+_\K.+/', $string, $m) ? $m[0] : null; } function viaPregReplace($string) { return preg_replace('/^\d+_/', '', $string); } function viaSscanf($string) { return sscanf($string, '%*d_%[^\d]')[0]; // because no numbers in trailing substring } foreach ($tests as $test => $desired) { printf( "%s: %s, %s, %s, %s, %s\n", str_pad($test, 25, ' '), viaLtrim($test), viaPregMatch($test), viaPregReplace($test), viaExplode($test), viaSscanf($test) ); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 34
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 34
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/Vdbk8
function name:  (null)
number of ops:  36
compiled vars:  !0 = $tests, !1 = $desired, !2 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   29     1      > FE_RESET_R                                       $4      !0, ->34
          2    > > FE_FETCH_R                                       ~5      $4, !1, ->34
          3    >   ASSIGN                                                   !2, ~5
   30     4        INIT_FCALL                                               'printf'
   31     5        SEND_VAL                                                 '%25s%3A+%25s%2C+%25s%2C+%25s%2C+%25s%2C+%25s%0A'
   32     6        INIT_FCALL                                               'str_pad'
          7        SEND_VAR                                                 !2
          8        SEND_VAL                                                 25
          9        SEND_VAL                                                 '+'
         10        DO_ICALL                                         $7      
         11        SEND_VAR                                                 $7
   33    12        INIT_FCALL                                               'vialtrim'
         13        SEND_VAR                                                 !2
         14        DO_FCALL                                      0  $8      
         15        SEND_VAR                                                 $8
   34    16        INIT_FCALL                                               'viapregmatch'
         17        SEND_VAR                                                 !2
         18        DO_FCALL                                      0  $9      
         19        SEND_VAR                                                 $9
   35    20        INIT_FCALL                                               'viapregreplace'
         21        SEND_VAR                                                 !2
         22        DO_FCALL                                      0  $10     
         23        SEND_VAR                                                 $10
   36    24        INIT_FCALL                                               'viaexplode'
         25        SEND_VAR                                                 !2
         26        DO_FCALL                                      0  $11     
         27        SEND_VAR                                                 $11
   37    28        INIT_FCALL                                               'viasscanf'
         29        SEND_VAR                                                 !2
         30        DO_FCALL                                      0  $12     
         31        SEND_VAR                                                 $12
   30    32        DO_ICALL                                                 
   29    33      > JMP                                                      ->2
         34    >   FE_FREE                                                  $4
   39    35      > RETURN                                                   1

Function viaexplode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Vdbk8
function name:  viaExplode
number of ops:  9
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '_'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 2
          5        DO_ICALL                                         $1      
          6        FETCH_DIM_R                                      ~2      $1, 1
          7      > RETURN                                                   ~2
   11     8*     > RETURN                                                   null

End of function viaexplode

Function vialtrim:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Vdbk8
function name:  viaLtrim
number of ops:  7
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     1        INIT_FCALL                                               'ltrim'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '0..9_'
          4        DO_ICALL                                         $1      
          5      > RETURN                                                   $1
   15     6*     > RETURN                                                   null

End of function vialtrim

Function viapregmatch:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Vdbk8
function name:  viaPregMatch
number of ops:  13
compiled vars:  !0 = $string, !1 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   18     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%2F%5Cd%2B_%5CK.%2B%2F'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                         $2      
          6      > JMPZ                                                     $2, ->10
          7    >   FETCH_DIM_R                                      ~3      !1, 0
          8        QM_ASSIGN                                        ~4      ~3
          9      > JMP                                                      ->11
         10    >   QM_ASSIGN                                        ~4      null
         11    > > RETURN                                                   ~4
   19    12*     > RETURN                                                   null

End of function viapregmatch

Function viapregreplace:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Vdbk8
function name:  viaPregReplace
number of ops:  8
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   22     1        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 '%2F%5E%5Cd%2B_%2F'
          3        SEND_VAL                                                 ''
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $1      
          6      > RETURN                                                   $1
   23     7*     > RETURN                                                   null

End of function viapregreplace

Function viasscanf:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Vdbk8
function name:  viaSscanf
number of ops:  8
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   26     1        INIT_FCALL                                               'sscanf'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '%25%2Ad_%25%5B%5E%5Cd%5D'
          4        DO_ICALL                                         $1      
          5        FETCH_DIM_R                                      ~2      $1, 0
          6      > RETURN                                                   ~2
   27     7*     > RETURN                                                   null

End of function viasscanf

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.19 ms | 1028 KiB | 25 Q