3v4l.org

run code in 300+ PHP versions simultaneously
<?php function startswith($haystack, $needle) { if (strlen($needle) > strlen($haystack)) { return false; } return substr($haystack, 0, strlen($needle)) === $needle; } function endswith($haystack, $needle) { if (strlen($needle) > strlen($haystack)) { return false; } $length = strlen($needle); return substr($haystack, -($length), $length) === $needle; } echo startswith('bla', 'bl') ? 'bla starts with bl' : 'bla does not start with bl'; echo PHP_EOL; echo endswith('bla', 'la') ? 'bla ends with la' : 'bla does not end with la'; echo PHP_EOL; echo endswith('bloop', 'la') ? 'bloop ends with la' : 'bloop does not end with la'; echo PHP_EOL; echo endswith('bloop', 'blablalba') ? 'bloop ends with blablalba' : 'bloop does not end with blablalba';
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
Branch analysis from position: 37
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
Branch analysis from position: 27
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
Branch analysis from position: 17
filename:       /in/GISut
function name:  (null)
number of ops:  40
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   INIT_FCALL                                               'startswith'
          1        SEND_VAL                                                 'bla'
          2        SEND_VAL                                                 'bl'
          3        DO_FCALL                                      0  $0      
          4      > JMPZ                                                     $0, ->7
          5    >   QM_ASSIGN                                        ~1      'bla+starts+with+bl'
          6      > JMP                                                      ->8
          7    >   QM_ASSIGN                                        ~1      'bla+does+not+start+with+bl'
          8    >   ECHO                                                     ~1
   18     9        ECHO                                                     '%0A'
   19    10        INIT_FCALL                                               'endswith'
         11        SEND_VAL                                                 'bla'
         12        SEND_VAL                                                 'la'
         13        DO_FCALL                                      0  $2      
         14      > JMPZ                                                     $2, ->17
         15    >   QM_ASSIGN                                        ~3      'bla+ends+with+la'
         16      > JMP                                                      ->18
         17    >   QM_ASSIGN                                        ~3      'bla+does+not+end+with+la'
         18    >   ECHO                                                     ~3
   20    19        ECHO                                                     '%0A'
   21    20        INIT_FCALL                                               'endswith'
         21        SEND_VAL                                                 'bloop'
         22        SEND_VAL                                                 'la'
         23        DO_FCALL                                      0  $4      
         24      > JMPZ                                                     $4, ->27
         25    >   QM_ASSIGN                                        ~5      'bloop+ends+with+la'
         26      > JMP                                                      ->28
         27    >   QM_ASSIGN                                        ~5      'bloop+does+not+end+with+la'
         28    >   ECHO                                                     ~5
   22    29        ECHO                                                     '%0A'
   23    30        INIT_FCALL                                               'endswith'
         31        SEND_VAL                                                 'bloop'
         32        SEND_VAL                                                 'blablalba'
         33        DO_FCALL                                      0  $6      
         34      > JMPZ                                                     $6, ->37
         35    >   QM_ASSIGN                                        ~7      'bloop+ends+with+blablalba'
         36      > JMP                                                      ->38
         37    >   QM_ASSIGN                                        ~7      'bloop+does+not+end+with+blablalba'
         38    >   ECHO                                                     ~7
         39      > RETURN                                                   1

Function startswith:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GISut
function name:  startswith
number of ops:  16
compiled vars:  !0 = $haystack, !1 = $needle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        STRLEN                                           ~2      !1
          3        STRLEN                                           ~3      !0
          4        IS_SMALLER                                               ~3, ~2
          5      > JMPZ                                                     ~4, ->7
    5     6    > > RETURN                                                   <false>
    7     7    >   INIT_FCALL                                               'substr'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 0
         10        STRLEN                                           ~5      !1
         11        SEND_VAL                                                 ~5
         12        DO_ICALL                                         $6      
         13        IS_IDENTICAL                                     ~7      !1, $6
         14      > RETURN                                                   ~7
    8    15*     > RETURN                                                   null

End of function startswith

Function endswith:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GISut
function name:  endswith
number of ops:  18
compiled vars:  !0 = $haystack, !1 = $needle, !2 = $length
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        STRLEN                                           ~3      !1
          3        STRLEN                                           ~4      !0
          4        IS_SMALLER                                               ~4, ~3
          5      > JMPZ                                                     ~5, ->7
   11     6    > > RETURN                                                   <false>
   13     7    >   STRLEN                                           ~6      !1
          8        ASSIGN                                                   !2, ~6
   14     9        INIT_FCALL                                               'substr'
         10        SEND_VAR                                                 !0
         11        MUL                                              ~8      !2, -1
         12        SEND_VAL                                                 ~8
         13        SEND_VAR                                                 !2
         14        DO_ICALL                                         $9      
         15        IS_IDENTICAL                                     ~10     !1, $9
         16      > RETURN                                                   ~10
   15    17*     > RETURN                                                   null

End of function endswith

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.21 ms | 1009 KiB | 18 Q