3v4l.org

run code in 500+ PHP versions simultaneously
<?php // the input $input = <<<STR section subsection text STR; // determine initial whitespace length preg_match('/^(?<initial>\s*)/', $input, $match); ['initial' => $initialWhiteSpace] = $match; $whiteSpaceLength = strlen($initialWhiteSpace); // convert string to array of lines $lines = explode(PHP_EOL, $input); // replace the white-space $output = array_map( static fn (string $str): string => preg_replace(sprintf("/^[ \t]{%d}/", $whiteSpaceLength), '', $str), $lines, ); // recreate the string $output = implode(PHP_EOL, $output); echo $output;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GoFbG
function name:  (null)
number of ops:  28
compiled vars:  !0 = $input, !1 = $match, !2 = $initialWhiteSpace, !3 = $whiteSpaceLength, !4 = $lines, !5 = $output
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   ASSIGN                                                       !0, '+++++section%0A++++++++subsection%0A++++++++++++text'
   13     1        INIT_FCALL                                                   'preg_match'
          2        SEND_VAL                                                     '%2F%5E%28%3F%3Cinitial%3E%5Cs%2A%29%2F'
          3        SEND_VAR                                                     !0
          4        SEND_REF                                                     !1
          5        DO_ICALL                                                     
   14     6        QM_ASSIGN                                            ~8      !1
          7        FETCH_LIST_R                                         $9      ~8, 'initial'
          8        ASSIGN                                                       !2, $9
          9        FREE                                                         ~8
   15    10        STRLEN                                               ~11     !2
         11        ASSIGN                                                       !3, ~11
   19    12        INIT_FCALL                                                   'explode'
         13        SEND_VAL                                                     '%0A'
         14        SEND_VAR                                                     !0
         15        DO_ICALL                                             $13     
         16        ASSIGN                                                       !4, $13
   24    17        INIT_FCALL                                                   'array_map'
   25    18        DECLARE_LAMBDA_FUNCTION                              ~15     [0]
         19        BIND_LEXICAL                                                 ~15, !3
         20        SEND_VAL                                                     ~15
   26    21        SEND_VAR                                                     !4
   24    22        DO_ICALL                                             $16     
         23        ASSIGN                                                       !5, $16
   31    24        FRAMELESS_ICALL_2                implode             ~18     '%0A', !5
         25        ASSIGN                                                       !5, ~18
   33    26        ECHO                                                         !5
   34    27      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GoFbG
function name:  {closure:/in/GoFbG:25}
number of ops:  12
compiled vars:  !0 = $str, !1 = $whiteSpaceLength
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   25     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
          2        ROPE_INIT                                         3  ~4      '%2F%5E%5B+%09%5D%7B'
          3        CAST                                              4  ~2      !1
          4        ROPE_ADD                                          1  ~4      ~4, ~2
          5        ROPE_END                                          2  ~3      ~4, '%7D%2F'
          6        FRAMELESS_ICALL_3                preg_replace        ~6      ~3, ''
          7        OP_DATA                                                      !0
          8        VERIFY_RETURN_TYPE                                           ~6
          9      > RETURN                                                       ~6
         10*       VERIFY_RETURN_TYPE                                           
         11*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
151.64 ms | 1891 KiB | 16 Q