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( 'http://', 'https://', '../', './', '//', '/' // $baseUrl ); foreach($search as $s) { $count = 0; $url = preg_replace('/^' . preg_quote($s, '/') . '/', $baseUrl, $url, 1, $count); if ($count == 1) { break; } } var_dump($url); return $url; $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/84KWC
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%2F84KWC%3A19%240'
          4        BIND_LEXICAL                                             ~7, !2
          5        ASSIGN                                                   !3, ~7
   76     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
   80    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                                 
         15      > RETURN                                                   1

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

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.57 ms | 1396 KiB | 27 Q