3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "This is a " . str_repeat("test", 2) . "!\n" . str_repeat("hello", 3) . " and Bye!\n" . "When I sleep, the thought bubble says " . str_repeat("zz", 3) . "."; function str_shrink($string, $needles) { $needles = array_map(function($needle) { return preg_quote($needle, '~'); }, $needles); return preg_replace_callback( '~\b(' . implode('|', $needles) . ')\1+\b~', function($m) { return "[{$m[1]}](" . (strlen($m[0]) / strlen($m[1])) . ")"; }, $string ); } echo str_shrink($string, ['test', 'hello']);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CiAWu
function name:  (null)
number of ops:  26
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'str_repeat'
          1        SEND_VAL                                                 'test'
          2        SEND_VAL                                                 2
          3        DO_ICALL                                         $1      
          4        CONCAT                                           ~2      'This+is+a+', $1
    4     5        CONCAT                                           ~3      ~2, '%21%0A'
          6        INIT_FCALL                                               'str_repeat'
          7        SEND_VAL                                                 'hello'
          8        SEND_VAL                                                 3
          9        DO_ICALL                                         $4      
         10        CONCAT                                           ~5      ~3, $4
         11        CONCAT                                           ~6      ~5, '+and+Bye%21%0A'
    5    12        CONCAT                                           ~7      ~6, 'When+I+sleep%2C+the+thought+bubble+says+'
         13        INIT_FCALL                                               'str_repeat'
         14        SEND_VAL                                                 'zz'
         15        SEND_VAL                                                 3
         16        DO_ICALL                                         $8      
         17        CONCAT                                           ~9      ~7, $8
         18        CONCAT                                           ~10     ~9, '.'
    3    19        ASSIGN                                                   !0, ~10
   21    20        INIT_FCALL                                               'str_shrink'
         21        SEND_VAR                                                 !0
         22        SEND_VAL                                                 <array>
         23        DO_FCALL                                      0  $12     
         24        ECHO                                                     $12
         25      > RETURN                                                   1

Function str_shrink:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CiAWu
function name:  str_shrink
number of ops:  22
compiled vars:  !0 = $string, !1 = $needles
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        INIT_FCALL                                               'array_map'
          3        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
   10     4        SEND_VAL                                                 ~2
          5        SEND_VAR                                                 !1
    8     6        DO_ICALL                                         $3      
          7        ASSIGN                                                   !1, $3
   12     8        INIT_FCALL                                               'preg_replace_callback'
   13     9        INIT_FCALL                                               'implode'
         10        SEND_VAL                                                 '%7C'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $5      
         13        CONCAT                                           ~6      '%7E%5Cb%28', $5
         14        CONCAT                                           ~7      ~6, '%29%5C1%2B%5Cb%7E'
         15        SEND_VAL                                                 ~7
   14    16        DECLARE_LAMBDA_FUNCTION                          ~8      [1]
   16    17        SEND_VAL                                                 ~8
   17    18        SEND_VAR                                                 !0
   12    19        DO_ICALL                                         $9      
   17    20      > RETURN                                                   $9
   19    21*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CiAWu
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $needle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
    9     1        INIT_FCALL                                               'preg_quote'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '%7E'
          4        DO_ICALL                                         $1      
          5      > RETURN                                                   $1
   10     6*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CiAWu
function name:  {closure}
number of ops:  14
compiled vars:  !0 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
   15     1        ROPE_INIT                                     3  ~3      '%5B'
          2        FETCH_DIM_R                                      ~1      !0, 1
          3        ROPE_ADD                                      1  ~3      ~3, ~1
          4        ROPE_END                                      2  ~2      ~3, '%5D%28'
          5        FETCH_DIM_R                                      ~5      !0, 0
          6        STRLEN                                           ~6      ~5
          7        FETCH_DIM_R                                      ~7      !0, 1
          8        STRLEN                                           ~8      ~7
          9        DIV                                              ~9      ~6, ~8
         10        CONCAT                                           ~10     ~2, ~9
         11        CONCAT                                           ~11     ~10, '%29'
         12      > RETURN                                                   ~11
   16    13*     > RETURN                                                   null

End of Dynamic Function 1

End of function str_shrink

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.76 ms | 1011 KiB | 19 Q