3v4l.org

run code in 300+ PHP versions simultaneously
<?php $patterns = array(); $patterns[]= '/(?:src|href)\=(?:\\\'|")([^\\\'"]+)(?:\\\'|")/'; $patterns[]= '/background\s*\:\s*url\s*\(\s*(?:\\\'|")([^\\\'"]+)(?:\\\'|")\s*\)/'; $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> <img src='./path/to/file' alt=''></a> <img src='www.sape.ru/path/to/file' alt=''></a> <img src='path/to/file.png' alt=''></a> <span style="background:url('path/to/url.jpg')"> 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 = $baseUrl . '/'; $resultUrl = $url; $count = 0; foreach($search as $s) { $count = 0; $resultUrl = preg_replace('/^' . preg_quote($s, '/') . '/', $baseUrlReplace, $url, 1, $count); if ($count == 1) { break; } } if (!$count) { $resultUrl = $baseUrlReplace . $url; } $search = array( '../', './' ); foreach($search as $s) { $resultUrl = preg_replace('/' . preg_quote($s, '/') . '/', '', $resultUrl); } $resultUrl = preg_replace('/\/{2,}/', '/', $resultUrl); $resultUrl = 'http://' . $resultUrl; var_dump($resultUrl); return str_replace($url, $resultUrl, $srcTag); }; $source = preg_replace_callback($patterns, $callback, $source); var_dump($source);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5v3NM
function name:  (null)
number of ops:  20
compiled vars:  !0 = $patterns, !1 = $source, !2 = $baseUrl, !3 = $callback
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN_DIM                                               !0
          2        OP_DATA                                                  '%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'
    7     3        ASSIGN_DIM                                               !0
          4        OP_DATA                                                  '%2Fbackground%5Cs%2A%5C%3A%5Cs%2Aurl%5Cs%2A%5C%28%5Cs%2A%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%5Cs%2A%5C%29%2F'
    9     5        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%0A%3Cimg+src%3D%27.%2Fpath%2Fto%2Ffile%27+alt%3D%27%27%3E%3C%2Fa%3E%0A%3Cimg+src%3D%27www.sape.ru%2Fpath%2Fto%2Ffile%27+alt%3D%27%27%3E%3C%2Fa%3E%0A%3Cimg+src%3D%27path%2Fto%2Ffile.png%27+alt%3D%27%27%3E%3C%2Fa%3E%0A%0A%3Cspan+style%3D%22background%3Aurl%28%27path%2Fto%2Furl.jpg%27%29%22%3E%0A'
   27     6        ASSIGN                                                   !2, 'www.sape.ru'
   29     7        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F5v3NM%3A29%240'
          8        BIND_LEXICAL                                             ~9, !2
          9        ASSIGN                                                   !3, ~9
   86    10        INIT_FCALL                                               'preg_replace_callback'
         11        SEND_VAR                                                 !0
         12        SEND_VAR                                                 !3
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $11     
         15        ASSIGN                                                   !1, $11
   90    16        INIT_FCALL                                               'var_dump'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                                 
         19      > RETURN                                                   1

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

End of function %00%7Bclosure%7D%2Fin%2F5v3NM%3A29%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.4 ms | 1404 KiB | 23 Q