3v4l.org

run code in 300+ PHP versions simultaneously
<?php $strings = [ 'StackOverFlow is the best site ever', // 22 ----------------^ 'http://stackoverflow.com is the best site ever', // 22 ----------------^ 'Short string', // no ellipsis needed ^ 'pneumonoultramicroscopicsilicovolcanoconiosis', // breakpoint between ^ letters ]; $link = '<a href="/this/story">Read More</a>'; function ShortenText($text, $chars) { $chars = $chars;$text = $text." "; $countchars = strlen($text); if($countchars > $chars) { $text = substr($text,0,$chars); $text = substr($text,0,strrpos($text,' ')); $text = $text."..."; } return $text; } foreach ($strings as $string) { var_export( ShortenText($string, 22) ); echo "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/VPl1V
function name:  (null)
number of ops:  15
compiled vars:  !0 = $strings, !1 = $link, !2 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   14     1        ASSIGN                                                   !1, '%3Ca+href%3D%22%2Fthis%2Fstory%22%3ERead+More%3C%2Fa%3E'
   29     2      > FE_RESET_R                                       $5      !0, ->13
          3    > > FE_FETCH_R                                               $5, !2, ->13
   30     4    >   INIT_FCALL                                               'var_export'
   31     5        INIT_FCALL                                               'shortentext'
          6        SEND_VAR                                                 !2
          7        SEND_VAL                                                 22
          8        DO_FCALL                                      0  $6      
          9        SEND_VAR                                                 $6
   30    10        DO_ICALL                                                 
   33    11        ECHO                                                     '%0A'
   29    12      > JMP                                                      ->3
         13    >   FE_FREE                                                  $5
   34    14      > RETURN                                                   1

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

End of function shortentext

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.51 ms | 1020 KiB | 17 Q