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) { var_dump('/' . preg_quote($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/T8dQi
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%2FT8dQi%3A19%240'
          4        BIND_LEXICAL                                             ~7, !2
          5        ASSIGN                                                   !3, ~7
   67     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
   71    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                                 
         15      > RETURN                                                   1

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

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
252.2 ms | 1404 KiB | 28 Q