3v4l.org

run code in 300+ PHP versions simultaneously
<?php $contents = <<<EOL console.log('hello'); //# sourceMappingURL= EOL; $backtrack_limit = (int) ini_get('pcre.backtrack_limit'); // Actual limit seems to be this value divided by 2. $backtrack_limit = ($backtrack_limit / 2) - 1; $contents .= str_repeat('x', $backtrack_limit); // Add an empty space after the sourcemap, followed by other code. $contents .= <<<EOL // I appear after the sourcemap. var newcode = 123; EOL; $results = [ 'orig' => preg_replace('/\/\/(#|@)\s(sourceURL|sourceMappingURL)=\s*(\S*?)\s*$/m', '', $contents), 'proposed' => preg_replace('/\/\/(#|@)\s(sourceURL|sourceMappingURL)=\s*[^$\s]*\s*$/m', '', $contents), 'alt1' => preg_replace('/\/\/(#|@)\s(sourceURL|sourceMappingURL)=.*\s*$/m', '', $contents), 'alt2' => preg_replace('/\/\/(#|@)\s(sourceURL|sourceMappingURL)=\s*[^$\s]*/m', '', $contents), // Most efficient so far based off https://regex101.com - (https://stackoverflow.com/a/36629670). 'alt3' => preg_replace('~//[#@]\s(source(?:Mapping)?URL)=\s*(\S+)~', '', $contents), ]; foreach ($results as $key => $result) { echo "------------------------------------------\n"; echo "Results for '$key':\n"; var_dump($result); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 47, Position 2 = 58
Branch analysis from position: 47
2 jumps found. (Code = 78) Position 1 = 48, Position 2 = 58
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 58
filename:       /in/JagL4
function name:  (null)
number of ops:  60
compiled vars:  !0 = $contents, !1 = $backtrack_limit, !2 = $results, !3 = $result, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'console.log%28%27hello%27%29%3B%0A%2F%2F%23+sourceMappingURL%3D'
    8     1        INIT_FCALL                                               'ini_get'
          2        SEND_VAL                                                 'pcre.backtrack_limit'
          3        DO_ICALL                                         $6      
          4        CAST                                          4  ~7      $6
          5        ASSIGN                                                   !1, ~7
   10     6        DIV                                              ~9      !1, 2
          7        SUB                                              ~10     ~9, 1
          8        ASSIGN                                                   !1, ~10
   12     9        INIT_FCALL                                               'str_repeat'
         10        SEND_VAL                                                 'x'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                         $12     
         13        ASSIGN_OP                                     8          !0, $12
   15    14        ASSIGN_OP                                     8          !0, '+%2F%2F+I+appear+after+the+sourcemap.%0Avar+newcode+%3D+123%3B'
   20    15        INIT_FCALL                                               'preg_replace'
         16        SEND_VAL                                                 '%2F%5C%2F%5C%2F%28%23%7C%40%29%5Cs%28sourceURL%7CsourceMappingURL%29%3D%5Cs%2A%28%5CS%2A%3F%29%5Cs%2A%24%2Fm'
         17        SEND_VAL                                                 ''
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                         $15     
         20        INIT_ARRAY                                       ~16     $15, 'orig'
   21    21        INIT_FCALL                                               'preg_replace'
         22        SEND_VAL                                                 '%2F%5C%2F%5C%2F%28%23%7C%40%29%5Cs%28sourceURL%7CsourceMappingURL%29%3D%5Cs%2A%5B%5E%24%5Cs%5D%2A%5Cs%2A%24%2Fm'
         23        SEND_VAL                                                 ''
         24        SEND_VAR                                                 !0
         25        DO_ICALL                                         $17     
         26        ADD_ARRAY_ELEMENT                                ~16     $17, 'proposed'
   22    27        INIT_FCALL                                               'preg_replace'
         28        SEND_VAL                                                 '%2F%5C%2F%5C%2F%28%23%7C%40%29%5Cs%28sourceURL%7CsourceMappingURL%29%3D.%2A%5Cs%2A%24%2Fm'
         29        SEND_VAL                                                 ''
         30        SEND_VAR                                                 !0
         31        DO_ICALL                                         $18     
         32        ADD_ARRAY_ELEMENT                                ~16     $18, 'alt1'
   23    33        INIT_FCALL                                               'preg_replace'
         34        SEND_VAL                                                 '%2F%5C%2F%5C%2F%28%23%7C%40%29%5Cs%28sourceURL%7CsourceMappingURL%29%3D%5Cs%2A%5B%5E%24%5Cs%5D%2A%2Fm'
         35        SEND_VAL                                                 ''
         36        SEND_VAR                                                 !0
         37        DO_ICALL                                         $19     
         38        ADD_ARRAY_ELEMENT                                ~16     $19, 'alt2'
   25    39        INIT_FCALL                                               'preg_replace'
         40        SEND_VAL                                                 '%7E%2F%2F%5B%23%40%5D%5Cs%28source%28%3F%3AMapping%29%3FURL%29%3D%5Cs%2A%28%5CS%2B%29%7E'
         41        SEND_VAL                                                 ''
         42        SEND_VAR                                                 !0
         43        DO_ICALL                                         $20     
         44        ADD_ARRAY_ELEMENT                                ~16     $20, 'alt3'
   19    45        ASSIGN                                                   !2, ~16
   28    46      > FE_RESET_R                                       $22     !2, ->58
         47    > > FE_FETCH_R                                       ~23     $22, !3, ->58
         48    >   ASSIGN                                                   !4, ~23
   29    49        ECHO                                                     '------------------------------------------%0A'
   30    50        ROPE_INIT                                     3  ~26     'Results+for+%27'
         51        ROPE_ADD                                      1  ~26     ~26, !4
         52        ROPE_END                                      2  ~25     ~26, '%27%3A%0A'
         53        ECHO                                                     ~25
   31    54        INIT_FCALL                                               'var_dump'
         55        SEND_VAR                                                 !3
         56        DO_ICALL                                                 
   28    57      > JMP                                                      ->47
         58    >   FE_FREE                                                  $22
   32    59      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.59 ms | 1019 KiB | 17 Q