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 ]; function word_wrap_custom($string, $limit) { $oneWord = explode(' ', $string); if(count($oneWord) < 2 ) return $oneWord[0]; $string = substr($string, 0, $limit + 2); $endchar = substr($string, $limit, $limit + 1); $postendchar = substr($string, $limit + 1, $limit + 2); $arrAccetpEndChar = array(' ', '!', '?', ',', '.', ';', ':'); if(in_array($postendchar, $arrAccetpEndChar) || in_array($endchar, $arrAccetpEndChar)) { return $string; } else { return preg_replace('/[A-Za-z0-9]+$/', '', $string); } } foreach ($strings as $string) { var_export( word_wrap_custom($string, 22) ); echo "\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 12
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/s4RvZ
function name:  (null)
number of ops:  14
compiled vars:  !0 = $strings, !1 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   36     1      > FE_RESET_R                                       $3      !0, ->12
          2    > > FE_FETCH_R                                               $3, !1, ->12
   37     3    >   INIT_FCALL                                               'var_export'
   38     4        INIT_FCALL                                               'word_wrap_custom'
          5        SEND_VAR                                                 !1
          6        SEND_VAL                                                 22
          7        DO_FCALL                                      0  $4      
          8        SEND_VAR                                                 $4
   37     9        DO_ICALL                                                 
   40    10        ECHO                                                     '%0A'
   36    11      > JMP                                                      ->2
         12    >   FE_FREE                                                  $3
   41    13      > RETURN                                                   1

Function word_wrap_custom:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 47) Position 1 = 40, Position 2 = 45
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 48
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
filename:       /in/s4RvZ
function name:  word_wrap_custom
number of ops:  55
compiled vars:  !0 = $string, !1 = $limit, !2 = $oneWord, !3 = $endchar, !4 = $postendchar, !5 = $arrAccetpEndChar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '+'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $6      
          6        ASSIGN                                                   !2, $6
   16     7        COUNT                                            ~8      !2
          8        IS_SMALLER                                               ~8, 2
          9      > JMPZ                                                     ~9, ->12
   17    10    >   FETCH_DIM_R                                      ~10     !2, 0
         11      > RETURN                                                   ~10
   18    12    >   INIT_FCALL                                               'substr'
         13        SEND_VAR                                                 !0
         14        SEND_VAL                                                 0
         15        ADD                                              ~11     !1, 2
         16        SEND_VAL                                                 ~11
         17        DO_ICALL                                         $12     
         18        ASSIGN                                                   !0, $12
   20    19        INIT_FCALL                                               'substr'
         20        SEND_VAR                                                 !0
         21        SEND_VAR                                                 !1
         22        ADD                                              ~14     !1, 1
         23        SEND_VAL                                                 ~14
         24        DO_ICALL                                         $15     
         25        ASSIGN                                                   !3, $15
   22    26        INIT_FCALL                                               'substr'
         27        SEND_VAR                                                 !0
         28        ADD                                              ~17     !1, 1
         29        SEND_VAL                                                 ~17
         30        ADD                                              ~18     !1, 2
         31        SEND_VAL                                                 ~18
         32        DO_ICALL                                         $19     
         33        ASSIGN                                                   !4, $19
   24    34        ASSIGN                                                   !5, <array>
   26    35        INIT_FCALL                                               'in_array'
         36        SEND_VAR                                                 !4
         37        SEND_VAR                                                 !5
         38        DO_ICALL                                         $22     
         39      > JMPNZ_EX                                         ~23     $22, ->45
         40    >   INIT_FCALL                                               'in_array'
         41        SEND_VAR                                                 !3
         42        SEND_VAR                                                 !5
         43        DO_ICALL                                         $24     
         44        BOOL                                             ~23     $24
         45    > > JMPZ                                                     ~23, ->48
   28    46    > > RETURN                                                   !0
   26    47*       JMP                                                      ->54
   32    48    >   INIT_FCALL                                               'preg_replace'
         49        SEND_VAL                                                 '%2F%5BA-Za-z0-9%5D%2B%24%2F'
         50        SEND_VAL                                                 ''
         51        SEND_VAR                                                 !0
         52        DO_ICALL                                         $25     
         53      > RETURN                                                   $25
   34    54*     > RETURN                                                   null

End of function word_wrap_custom

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
260.56 ms | 1022 KiB | 19 Q