3v4l.org

run code in 300+ PHP versions simultaneously
<?php function formatTitle($sku, $name, $brand, $maximumLength = 100) { $allowedLength = $maximumLength - 6 - mb_strlen($brand, 'UTF-8') - mb_strlen($sku, 'UTF-8'); if (mb_strlen($name) > $allowedLength) { $startLength = floor($allowedLength / 3 * 2) - 5; $name = mb_substr($name, 0, $startLength) . '[...]' . mb_substr($name, -($allowedLength - $startLength + 5)); var_dump( mb_strlen($brand, 'UTF-8'), mb_strlen($sku, 'UTF-8'), $allowedLength, $startLength, -($allowedLength - $startLength + 5) ); } return sprintf('%s | %s | %s', $sku, $name, $brand); } var_dump(strlen(formatTitle('TFT10000', substr("Lorem ipsum dolor sit amet consecutir, lorem ipsum dolor sit amet consecutir, lorem ipsum dolor sit amet consecutir, lorem ipsum dolor sit amet consecutir", 0, 100), 'Les french demoiselles')));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5Lgtl
function name:  (null)
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'formattitle'
          2        SEND_VAL                                                 'TFT10000'
          3        INIT_FCALL                                               'substr'
          4        SEND_VAL                                                 'Lorem+ipsum+dolor+sit+amet+consecutir%2C+lorem+ipsum+dolor+sit+amet+consecutir%2C+lorem+ipsum+dolor+sit+amet+consecutir%2C+lorem+ipsum+dolor+sit+amet+consecutir'
          5        SEND_VAL                                                 0
          6        SEND_VAL                                                 100
          7        DO_ICALL                                         $0      
          8        SEND_VAR                                                 $0
          9        SEND_VAL                                                 'Les+french+demoiselles'
         10        DO_FCALL                                      0  $1      
         11        STRLEN                                           ~2      $1
         12        SEND_VAL                                                 ~2
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Function formattitle:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 61
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 61
filename:       /in/5Lgtl
function name:  formatTitle
number of ops:  69
compiled vars:  !0 = $sku, !1 = $name, !2 = $brand, !3 = $maximumLength, !4 = $allowedLength, !5 = $startLength
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      100
    6     4        SUB                                              ~6      !3, 6
          5        INIT_FCALL                                               'mb_strlen'
          6        SEND_VAR                                                 !2
          7        SEND_VAL                                                 'UTF-8'
          8        DO_ICALL                                         $7      
          9        SUB                                              ~8      ~6, $7
         10        INIT_FCALL                                               'mb_strlen'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 'UTF-8'
         13        DO_ICALL                                         $9      
         14        SUB                                              ~10     ~8, $9
         15        ASSIGN                                                   !4, ~10
    8    16        INIT_FCALL                                               'mb_strlen'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $12     
         19        IS_SMALLER                                               !4, $12
         20      > JMPZ                                                     ~13, ->61
    9    21    >   INIT_FCALL                                               'floor'
         22        DIV                                              ~14     !4, 3
         23        MUL                                              ~15     ~14, 2
         24        SEND_VAL                                                 ~15
         25        DO_ICALL                                         $16     
         26        SUB                                              ~17     $16, 5
         27        ASSIGN                                                   !5, ~17
   10    28        INIT_FCALL                                               'mb_substr'
         29        SEND_VAR                                                 !1
         30        SEND_VAL                                                 0
         31        SEND_VAR                                                 !5
         32        DO_ICALL                                         $19     
         33        CONCAT                                           ~20     $19, '%5B...%5D'
   11    34        INIT_FCALL                                               'mb_substr'
         35        SEND_VAR                                                 !1
         36        SUB                                              ~21     !4, !5
         37        ADD                                              ~22     ~21, 5
         38        MUL                                              ~23     ~22, -1
         39        SEND_VAL                                                 ~23
         40        DO_ICALL                                         $24     
         41        CONCAT                                           ~25     ~20, $24
   10    42        ASSIGN                                                   !1, ~25
   12    43        INIT_FCALL                                               'var_dump'
   13    44        INIT_FCALL                                               'mb_strlen'
         45        SEND_VAR                                                 !2
         46        SEND_VAL                                                 'UTF-8'
         47        DO_ICALL                                         $27     
         48        SEND_VAR                                                 $27
   14    49        INIT_FCALL                                               'mb_strlen'
         50        SEND_VAR                                                 !0
         51        SEND_VAL                                                 'UTF-8'
         52        DO_ICALL                                         $28     
         53        SEND_VAR                                                 $28
   15    54        SEND_VAR                                                 !4
   16    55        SEND_VAR                                                 !5
   17    56        SUB                                              ~29     !4, !5
         57        ADD                                              ~30     ~29, 5
         58        MUL                                              ~31     ~30, -1
         59        SEND_VAL                                                 ~31
   12    60        DO_ICALL                                                 
   21    61    >   INIT_FCALL                                               'sprintf'
         62        SEND_VAL                                                 '%25s+%7C+%25s+%7C+%25s'
         63        SEND_VAR                                                 !0
         64        SEND_VAR                                                 !1
         65        SEND_VAR                                                 !2
         66        DO_ICALL                                         $33     
         67      > RETURN                                                   $33
   22    68*     > RETURN                                                   null

End of function formattitle

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
286.25 ms | 1023 KiB | 20 Q