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(-($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/Cu9fW
function name:  (null)
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     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 = 49
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 49
filename:       /in/Cu9fW
function name:  formatTitle
number of ops:  57
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, ->49
    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'
         44        SUB                                              ~27     !4, !5
         45        ADD                                              ~28     ~27, 5
         46        MUL                                              ~29     ~28, -1
         47        SEND_VAL                                                 ~29
         48        DO_ICALL                                                 
   15    49    >   INIT_FCALL                                               'sprintf'
         50        SEND_VAL                                                 '%25s+%7C+%25s+%7C+%25s'
         51        SEND_VAR                                                 !0
         52        SEND_VAR                                                 !1
         53        SEND_VAR                                                 !2
         54        DO_ICALL                                         $31     
         55      > RETURN                                                   $31
   16    56*     > RETURN                                                   null

End of function formattitle

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.46 ms | 1023 KiB | 20 Q