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) { $url = preg_replace('/' . preg_quote($s, '/') . '/', '', $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/qbToA
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%2FqbToA%3A19%240'
          4        BIND_LEXICAL                                             ~7, !2
          5        ASSIGN                                                   !3, ~7
   66     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
   70    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                                 
         15      > RETURN                                                   1

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

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.2 ms | 1404 KiB | 27 Q