3v4l.org

run code in 300+ PHP versions simultaneously
<?php function truncate($text, $max) { if (strlen($text) >= $max) { $text = ereg_replace("<[^>]*>", "", $text); $text = substr($text, 0, $max); $position = strrpos($text, " "); $text = substr($text, 0, $position)."..."; } return $text; } echo truncate('Lorem ipsum dolor <span>sit</span> amet !', 25); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DOBMv
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   INIT_FCALL                                               'truncate'
          1        SEND_VAL                                                 'Lorem+ipsum+dolor+%3Cspan%3Esit%3C%2Fspan%3E+amet+%21'
          2        SEND_VAL                                                 25
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
   12     5      > RETURN                                                   1

Function truncate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 29
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/DOBMv
function name:  truncate
number of ops:  31
compiled vars:  !0 = $text, !1 = $max, !2 = $position
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    3     2        STRLEN                                           ~3      !0
          3        IS_SMALLER_OR_EQUAL                                      !1, ~3
          4      > JMPZ                                                     ~4, ->29
    4     5    >   INIT_FCALL_BY_NAME                                       'ereg_replace'
          6        SEND_VAL_EX                                              '%3C%5B%5E%3E%5D%2A%3E'
          7        SEND_VAL_EX                                              ''
          8        SEND_VAR_EX                                              !0
          9        DO_FCALL                                      0  $5      
         10        ASSIGN                                                   !0, $5
    5    11        INIT_FCALL                                               'substr'
         12        SEND_VAR                                                 !0
         13        SEND_VAL                                                 0
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                         $7      
         16        ASSIGN                                                   !0, $7
    6    17        INIT_FCALL                                               'strrpos'
         18        SEND_VAR                                                 !0
         19        SEND_VAL                                                 '+'
         20        DO_ICALL                                         $9      
         21        ASSIGN                                                   !2, $9
    7    22        INIT_FCALL                                               'substr'
         23        SEND_VAR                                                 !0
         24        SEND_VAL                                                 0
         25        SEND_VAR                                                 !2
         26        DO_ICALL                                         $11     
         27        CONCAT                                           ~12     $11, '...'
         28        ASSIGN                                                   !0, ~12
    9    29    > > RETURN                                                   !0
   10    30*     > RETURN                                                   null

End of function truncate

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.26 ms | 1398 KiB | 18 Q