3v4l.org

run code in 300+ PHP versions simultaneously
<?php $pattern = '/(?:src|href)\=(?:\\\'|")([^\\\'"]+)(?:\\\'|")/'; $source = <<<SRC <a href="http://www.sape.ru">some text</a> <img src='logo.jpg' alt=''></a> <img src='../../logo.jpg' alt=''></a> <img src='/path/to/file' alt=''></a> SRC; $baseUrl = 'www.sape.ru'; $callback = function($matches) use ($baseUrl) { $srcTag = $matches[0]; $url = $matches[1]; $search = array( $baseUrl, 'http://' . $baseUrl, 'https://' . $baseUrl, 'http://', 'https://', '../', './', '//', '/' ); $baseUrlReplace = 'http://' . $baseUrl; $resultUrl = $url; foreach($search as $s) { $count = 0; $resultUrl = preg_replace('/^' . preg_quote($s, '/') . '/', $baseUrlReplace, $url, 1, $count); if ($count == 1) { break; } } var_dump($resultUrl); return str_replace($url, $resultUrl, $srcTag); $url = preg_replace('/^[^\/]\//', '/', $url); $path = parse_url($url, PHP_URL_PATH); //if (empty($path)) { // $path = '/'; //} $query = parse_url($url, PHP_URL_QUERY); if (!empty($query)) { $path.= '?' . $query; } $fragment = parse_url($url, PHP_URL_FRAGMENT); if (!empty($fragment)) { $path.= '#' . $fragment; } $resultUrl = 'http://' . $baseUrl . '/' . ltrim($path, '/'); //var_dump($resultUrl); return str_replace($url, $resultUrl, $srcTag); }; $source = preg_replace_callback($pattern, $callback, $source); var_dump($source);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1Dnda
function name:  (null)
number of ops:  16
compiled vars:  !0 = $pattern, !1 = $source, !2 = $baseUrl, !3 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%2F%28%3F%3Asrc%7Chref%29%5C%3D%28%3F%3A%5C%27%7C%22%29%28%5B%5E%5C%27%22%5D%2B%29%28%3F%3A%5C%27%7C%22%29%2F'
    5     1        ASSIGN                                                   !1, '%0A%3Ca+href%3D%22http%3A%2F%2Fwww.sape.ru%22%3Esome+text%3C%2Fa%3E%0A%0A%3Cimg+src%3D%27logo.jpg%27+alt%3D%27%27%3E%3C%2Fa%3E%0A%0A%3Cimg+src%3D%27..%2F..%2Flogo.jpg%27+alt%3D%27%27%3E%3C%2Fa%3E%0A%3Cimg+src%3D%27%2Fpath%2Fto%2Ffile%27+alt%3D%27%27%3E%3C%2Fa%3E%0A'
   17     2        ASSIGN                                                   !2, 'www.sape.ru'
   19     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F1Dnda%3A19%240'
          4        BIND_LEXICAL                                             ~7, !2
          5        ASSIGN                                                   !3, ~7
   82     6        INIT_FCALL                                               'preg_replace_callback'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !3
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $9      
         11        ASSIGN                                                   !1, $9
   86    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                                 
         15      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F1Dnda%3A19%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 42
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 42
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 41
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 42
Branch analysis from position: 42
filename:       /in/1Dnda
function name:  {closure}
number of ops:  98
compiled vars:  !0 = $matches, !1 = $baseUrl, !2 = $srcTag, !3 = $url, !4 = $search, !5 = $baseUrlReplace, !6 = $resultUrl, !7 = $s, !8 = $count, !9 = $path, !10 = $query, !11 = $fragment
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   21     2        FETCH_DIM_R                                      ~12     !0, 0
          3        ASSIGN                                                   !2, ~12
   22     4        FETCH_DIM_R                                      ~14     !0, 1
          5        ASSIGN                                                   !3, ~14
   25     6        INIT_ARRAY                                       ~16     !1
   26     7        CONCAT                                           ~17     'http%3A%2F%2F', !1
          8        ADD_ARRAY_ELEMENT                                ~16     ~17
   27     9        CONCAT                                           ~18     'https%3A%2F%2F', !1
         10        ADD_ARRAY_ELEMENT                                ~16     ~18
   28    11        ADD_ARRAY_ELEMENT                                ~16     'http%3A%2F%2F'
   29    12        ADD_ARRAY_ELEMENT                                ~16     'https%3A%2F%2F'
   30    13        ADD_ARRAY_ELEMENT                                ~16     '..%2F'
   31    14        ADD_ARRAY_ELEMENT                                ~16     '.%2F'
   32    15        ADD_ARRAY_ELEMENT                                ~16     '%2F%2F'
   33    16        ADD_ARRAY_ELEMENT                                ~16     '%2F'
   24    17        ASSIGN                                                   !4, ~16
   37    18        CONCAT                                           ~20     'http%3A%2F%2F', !1
         19        ASSIGN                                                   !5, ~20
   39    20        ASSIGN                                                   !6, !3
   41    21      > FE_RESET_R                                       $23     !4, ->42
         22    > > FE_FETCH_R                                               $23, !7, ->42
   42    23    >   ASSIGN                                                   !8, 0
   43    24        INIT_FCALL                                               'preg_replace'
         25        INIT_FCALL                                               'preg_quote'
         26        SEND_VAR                                                 !7
         27        SEND_VAL                                                 '%2F'
         28        DO_ICALL                                         $25     
         29        CONCAT                                           ~26     '%2F%5E', $25
         30        CONCAT                                           ~27     ~26, '%2F'
         31        SEND_VAL                                                 ~27
         32        SEND_VAR                                                 !5
         33        SEND_VAR                                                 !3
         34        SEND_VAL                                                 1
         35        SEND_REF                                                 !8
         36        DO_ICALL                                         $28     
         37        ASSIGN                                                   !6, $28
   44    38        IS_EQUAL                                                 !8, 1
         39      > JMPZ                                                     ~30, ->41
   45    40    > > JMP                                                      ->42
   41    41    > > JMP                                                      ->22
         42    >   FE_FREE                                                  $23
   49    43        INIT_FCALL                                               'var_dump'
         44        SEND_VAR                                                 !6
         45        DO_ICALL                                                 
   52    46        INIT_FCALL                                               'str_replace'
         47        SEND_VAR                                                 !3
         48        SEND_VAR                                                 !6
         49        SEND_VAR                                                 !2
         50        DO_ICALL                                         $32     
         51      > RETURN                                                   $32
   54    52*       INIT_FCALL                                               'preg_replace'
         53*       SEND_VAL                                                 '%2F%5E%5B%5E%5C%2F%5D%5C%2F%2F'
         54*       SEND_VAL                                                 '%2F'
         55*       SEND_VAR                                                 !3
         56*       DO_ICALL                                         $33     
         57*       ASSIGN                                                   !3, $33
   57    58*       INIT_FCALL                                               'parse_url'
         59*       SEND_VAR                                                 !3
         60*       SEND_VAL                                                 5
         61*       DO_ICALL                                         $35     
         62*       ASSIGN                                                   !9, $35
   62    63*       INIT_FCALL                                               'parse_url'
         64*       SEND_VAR                                                 !3
         65*       SEND_VAL                                                 6
         66*       DO_ICALL                                         $37     
         67*       ASSIGN                                                   !10, $37
   63    68*       ISSET_ISEMPTY_CV                                 ~39     !10
         69*       BOOL_NOT                                         ~40     ~39
         70*       JMPZ                                                     ~40, ->73
   64    71*       CONCAT                                           ~41     '%3F', !10
         72*       ASSIGN_OP                                     8          !9, ~41
   68    73*       INIT_FCALL                                               'parse_url'
         74*       SEND_VAR                                                 !3
         75*       SEND_VAL                                                 7
         76*       DO_ICALL                                         $43     
         77*       ASSIGN                                                   !11, $43
   69    78*       ISSET_ISEMPTY_CV                                 ~45     !11
         79*       BOOL_NOT                                         ~46     ~45
         80*       JMPZ                                                     ~46, ->83
   70    81*       CONCAT                                           ~47     '%23', !11
         82*       ASSIGN_OP                                     8          !9, ~47
   74    83*       CONCAT                                           ~49     'http%3A%2F%2F', !1
         84*       CONCAT                                           ~50     ~49, '%2F'
         85*       INIT_FCALL                                               'ltrim'
         86*       SEND_VAR                                                 !9
         87*       SEND_VAL                                                 '%2F'
         88*       DO_ICALL                                         $51     
         89*       CONCAT                                           ~52     ~50, $51
         90*       ASSIGN                                                   !6, ~52
   78    91*       INIT_FCALL                                               'str_replace'
         92*       SEND_VAR                                                 !3
         93*       SEND_VAR                                                 !6
         94*       SEND_VAR                                                 !2
         95*       DO_ICALL                                         $54     
         96*       RETURN                                                   $54
   80    97*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F1Dnda%3A19%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.38 ms | 1404 KiB | 27 Q