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 ); $url = str_replace($search, '', $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 = $baseUrl . '/' . $path; var_dump($resultUrl); return $resultUrl; }; preg_replace_callback($pattern, $callback, $source);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CKIGS
function name:  (null)
number of ops:  12
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%2FCKIGS%3A19%240'
          4        BIND_LEXICAL                                             ~7, !2
          5        ASSIGN                                                   !3, ~7
   64     6        INIT_FCALL                                               'preg_replace_callback'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !3
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                                 
         11      > RETURN                                                   1

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

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150 ms | 1400 KiB | 23 Q