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; foreach($search as $s) { $count = 0; $url = preg_replace('/^' . preg_quote($s, '/') . '/', $baseUrlReplace, $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/bZHA6
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%2FbZHA6%3A19%240'
          4        BIND_LEXICAL                                             ~7, !2
          5        ASSIGN                                                   !3, ~7
   80     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
   84    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                                 
         15      > RETURN                                                   1

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

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.37 ms | 1404 KiB | 27 Q