3v4l.org

run code in 300+ PHP versions simultaneously
<?php function str_truncat($string, $nbrchar = 50, $charsfin = "", $addstrfin = "...") { if($charsfin == "" && strlen(strip_tags($string)) < $nbrchar) { $stringtruncat = strip_tags($string); } else { $nbr = ($nbrchar)/250; $addchars = ""; if($nbr > 1) { for($i = 0;$i < (int)$nbr;$i++) { $nbrchar -= 250; $addchars .= ".{250}"; } } $addchars .= ".{".$nbrchar."}"; $str1 = preg_replace("(\[+[a-z0-9]+\]{1,2})", "", str_replace("\n"," ",strip_tags($string))); $str2 = preg_replace("(\[+[a-zA-Z:0-9]+[ |]([^\]]+)*\]+)", "\\1 ", $str1); $preg = "/^(".$addchars.($charsfin?"[^".$charsfin."]*":"").").*$/"; $str3 = preg_replace($preg, "\\1".$addstrfin, $str2); $stringtruncat = preg_replace("/ ".str_replace(".", "\.", $addstrfin)."$/", $addstrfin, $str3); } return htmlspecialchars($stringtruncat, ENT_COMPAT | ENT_HTML401, 'ISO-8859-1'); } $var = "LG 47LA640S859 € dont 8 &euro d'écocontribution"; $var = html_entity_decode($var, ENT_COMPAT | ENT_HTML401, 'ISO-8859-1'); $var = str_truncat($var); echo $var;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OHeRX
function name:  (null)
number of ops:  13
compiled vars:  !0 = $var
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   ASSIGN                                                   !0, 'LG+47LA640S859+%E2%82%AC+dont+8+%26euro+d%27%C3%A9cocontribution'
   28     1        INIT_FCALL                                               'html_entity_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 2
          4        SEND_VAL                                                 'ISO-8859-1'
          5        DO_ICALL                                         $2      
          6        ASSIGN                                                   !0, $2
   29     7        INIT_FCALL                                               'str_truncat'
          8        SEND_VAR                                                 !0
          9        DO_FCALL                                      0  $4      
         10        ASSIGN                                                   !0, $4
   32    11        ECHO                                                     !0
         12      > RETURN                                                   1

Function str_truncat:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 18
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 84
Branch analysis from position: 84
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 31
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 25
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 60
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 25
Branch analysis from position: 31
Branch analysis from position: 25
Branch analysis from position: 31
Branch analysis from position: 12
filename:       /in/OHeRX
function name:  str_truncat
number of ops:  91
compiled vars:  !0 = $string, !1 = $nbrchar, !2 = $charsfin, !3 = $addstrfin, !4 = $stringtruncat, !5 = $nbr, !6 = $addchars, !7 = $i, !8 = $str1, !9 = $str2, !10 = $preg, !11 = $str3
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      50
          2        RECV_INIT                                        !2      ''
          3        RECV_INIT                                        !3      '...'
    4     4        IS_EQUAL                                         ~12     !2, ''
          5      > JMPZ_EX                                          ~12     ~12, ->12
          6    >   INIT_FCALL                                               'strip_tags'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $13     
          9        STRLEN                                           ~14     $13
         10        IS_SMALLER                                       ~15     ~14, !1
         11        BOOL                                             ~12     ~15
         12    > > JMPZ                                                     ~12, ->18
    5    13    >   INIT_FCALL                                               'strip_tags'
         14        SEND_VAR                                                 !0
         15        DO_ICALL                                         $16     
         16        ASSIGN                                                   !4, $16
         17      > JMP                                                      ->84
    8    18    >   DIV                                              ~18     !1, 250
         19        ASSIGN                                                   !5, ~18
    9    20        ASSIGN                                                   !6, ''
   10    21        IS_SMALLER                                               1, !5
         22      > JMPZ                                                     ~21, ->31
   11    23    >   ASSIGN                                                   !7, 0
         24      > JMP                                                      ->28
   12    25    >   ASSIGN_OP                                     2          !1, 250
   13    26        ASSIGN_OP                                     8          !6, '.%7B250%7D'
   11    27        PRE_INC                                                  !7
         28    >   CAST                                          4  ~26     !5
         29        IS_SMALLER                                               !7, ~26
         30      > JMPNZ                                                    ~27, ->25
   16    31    >   CONCAT                                           ~28     '.%7B', !1
         32        CONCAT                                           ~29     ~28, '%7D'
         33        ASSIGN_OP                                     8          !6, ~29
   17    34        INIT_FCALL                                               'preg_replace'
         35        SEND_VAL                                                 '%28%5C%5B%2B%5Ba-z0-9%5D%2B%5C%5D%7B1%2C2%7D%29'
         36        SEND_VAL                                                 ''
         37        INIT_FCALL                                               'str_replace'
         38        SEND_VAL                                                 '%0A'
         39        SEND_VAL                                                 '+'
         40        INIT_FCALL                                               'strip_tags'
         41        SEND_VAR                                                 !0
         42        DO_ICALL                                         $31     
         43        SEND_VAR                                                 $31
         44        DO_ICALL                                         $32     
         45        SEND_VAR                                                 $32
         46        DO_ICALL                                         $33     
         47        ASSIGN                                                   !8, $33
   18    48        INIT_FCALL                                               'preg_replace'
         49        SEND_VAL                                                 '%28%5C%5B%2B%5Ba-zA-Z%3A0-9%5D%2B%5B+%7C%5D%28%5B%5E%5C%5D%5D%2B%29%2A%5C%5D%2B%29'
         50        SEND_VAL                                                 '%5C1+'
         51        SEND_VAR                                                 !8
         52        DO_ICALL                                         $35     
         53        ASSIGN                                                   !9, $35
   19    54        CONCAT                                           ~37     '%2F%5E%28', !6
         55      > JMPZ                                                     !2, ->60
         56    >   CONCAT                                           ~38     '%5B%5E', !2
         57        CONCAT                                           ~39     ~38, '%5D%2A'
         58        QM_ASSIGN                                        ~40     ~39
         59      > JMP                                                      ->61
         60    >   QM_ASSIGN                                        ~40     ''
         61    >   CONCAT                                           ~41     ~37, ~40
         62        CONCAT                                           ~42     ~41, '%29.%2A%24%2F'
         63        ASSIGN                                                   !10, ~42
   20    64        INIT_FCALL                                               'preg_replace'
         65        SEND_VAR                                                 !10
         66        CONCAT                                           ~44     '%5C1', !3
         67        SEND_VAL                                                 ~44
         68        SEND_VAR                                                 !9
         69        DO_ICALL                                         $45     
         70        ASSIGN                                                   !11, $45
   21    71        INIT_FCALL                                               'preg_replace'
         72        INIT_FCALL                                               'str_replace'
         73        SEND_VAL                                                 '.'
         74        SEND_VAL                                                 '%5C.'
         75        SEND_VAR                                                 !3
         76        DO_ICALL                                         $47     
         77        CONCAT                                           ~48     '%2F+', $47
         78        CONCAT                                           ~49     ~48, '%24%2F'
         79        SEND_VAL                                                 ~49
         80        SEND_VAR                                                 !3
         81        SEND_VAR                                                 !11
         82        DO_ICALL                                         $50     
         83        ASSIGN                                                   !4, $50
   24    84    >   INIT_FCALL                                               'htmlspecialchars'
         85        SEND_VAR                                                 !4
         86        SEND_VAL                                                 2
         87        SEND_VAL                                                 'ISO-8859-1'
         88        DO_ICALL                                         $52     
         89      > RETURN                                                   $52
   25    90*     > RETURN                                                   null

End of function str_truncat

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.63 ms | 1407 KiB | 24 Q