3v4l.org

run code in 300+ PHP versions simultaneously
<?php $output = "hello Mary."; $suffix = "added text to crop on condition"; $output .=$suffix; //append suffix to output $condition = true; // change to false to simulate case where no cropping is needed if($condition){ $suffix_len = strlen($suffix); //length of the suffix $output_len = strlen($output); //length of the whole output (including suffix) //if suffix is found at the end of the output if(substr($output,$output_len-$suffix_len) == $suffix){ $output = substr($output,0,$output_len-$suffix_len); //crop } } echo $output;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 23
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 23
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
Branch analysis from position: 23
filename:       /in/22JTs
function name:  (null)
number of ops:  25
compiled vars:  !0 = $output, !1 = $suffix, !2 = $condition, !3 = $suffix_len, !4 = $output_len
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'hello+Mary.'
    4     1        ASSIGN                                                   !1, 'added+text+to+crop+on+condition'
    5     2        ASSIGN_OP                                     8          !0, !1
    6     3        ASSIGN                                                   !2, <true>
    8     4      > JMPZ                                                     !2, ->23
    9     5    >   STRLEN                                           ~9      !1
          6        ASSIGN                                                   !3, ~9
   10     7        STRLEN                                           ~11     !0
          8        ASSIGN                                                   !4, ~11
   13     9        INIT_FCALL                                               'substr'
         10        SEND_VAR                                                 !0
         11        SUB                                              ~13     !4, !3
         12        SEND_VAL                                                 ~13
         13        DO_ICALL                                         $14     
         14        IS_EQUAL                                                 !1, $14
         15      > JMPZ                                                     ~15, ->23
   14    16    >   INIT_FCALL                                               'substr'
         17        SEND_VAR                                                 !0
         18        SEND_VAL                                                 0
         19        SUB                                              ~16     !4, !3
         20        SEND_VAL                                                 ~16
         21        DO_ICALL                                         $17     
         22        ASSIGN                                                   !0, $17
   17    23    >   ECHO                                                     !0
         24      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
232.89 ms | 1010 KiB | 14 Q