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> SRC; $baseUrl = 'http://www.sape.ru'; $callback = function($matches) use ($baseUrl) { $srcTag = $matches[0]; $url = $matches[1]; $url = str_replace('http://', '', $url); $url = str_replace('https://', '', $url); $url = str_replace('../', '', $url); $url = str_replace('./', '', $url); $url = str_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($baseUrl, $path); 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/XIQTN
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'
   14     2        ASSIGN                                                   !2, 'http%3A%2F%2Fwww.sape.ru'
   16     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FXIQTN%3A16%240'
          4        BIND_LEXICAL                                             ~7, !2
          5        ASSIGN                                                   !3, ~7
   53     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%2FXIQTN%3A16%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 44
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 54
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 62, Position 2 = 64
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 64
Branch analysis from position: 54
Branch analysis from position: 44
filename:       /in/XIQTN
function name:  {closure}
number of ops:  72
compiled vars:  !0 = $matches, !1 = $baseUrl, !2 = $srcTag, !3 = $url, !4 = $path, !5 = $query, !6 = $fragment, !7 = $resultUrl
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   18     2        FETCH_DIM_R                                      ~8      !0, 0
          3        ASSIGN                                                   !2, ~8
   19     4        FETCH_DIM_R                                      ~10     !0, 1
          5        ASSIGN                                                   !3, ~10
   21     6        INIT_FCALL                                               'str_replace'
          7        SEND_VAL                                                 'http%3A%2F%2F'
          8        SEND_VAL                                                 ''
          9        SEND_VAR                                                 !3
         10        DO_ICALL                                         $12     
         11        ASSIGN                                                   !3, $12
   22    12        INIT_FCALL                                               'str_replace'
         13        SEND_VAL                                                 'https%3A%2F%2F'
         14        SEND_VAL                                                 ''
         15        SEND_VAR                                                 !3
         16        DO_ICALL                                         $14     
         17        ASSIGN                                                   !3, $14
   23    18        INIT_FCALL                                               'str_replace'
         19        SEND_VAL                                                 '..%2F'
         20        SEND_VAL                                                 ''
         21        SEND_VAR                                                 !3
         22        DO_ICALL                                         $16     
         23        ASSIGN                                                   !3, $16
   24    24        INIT_FCALL                                               'str_replace'
         25        SEND_VAL                                                 '.%2F'
         26        SEND_VAL                                                 ''
         27        SEND_VAR                                                 !3
         28        DO_ICALL                                         $18     
         29        ASSIGN                                                   !3, $18
   25    30        INIT_FCALL                                               'str_replace'
         31        SEND_VAL                                                 '%2F%2F'
         32        SEND_VAL                                                 ''
         33        SEND_VAR                                                 !3
         34        DO_ICALL                                         $20     
         35        ASSIGN                                                   !3, $20
   28    36        INIT_FCALL                                               'parse_url'
         37        SEND_VAR                                                 !3
         38        SEND_VAL                                                 5
         39        DO_ICALL                                         $22     
         40        ASSIGN                                                   !4, $22
   29    41        ISSET_ISEMPTY_CV                                         !4
         42      > JMPZ                                                     ~24, ->44
   30    43    >   ASSIGN                                                   !4, '%2F'
   33    44    >   INIT_FCALL                                               'parse_url'
         45        SEND_VAR                                                 !3
         46        SEND_VAL                                                 6
         47        DO_ICALL                                         $26     
         48        ASSIGN                                                   !5, $26
   34    49        ISSET_ISEMPTY_CV                                 ~28     !5
         50        BOOL_NOT                                         ~29     ~28
         51      > JMPZ                                                     ~29, ->54
   35    52    >   CONCAT                                           ~30     '%3F', !5
         53        ASSIGN_OP                                     8          !4, ~30
   39    54    >   INIT_FCALL                                               'parse_url'
         55        SEND_VAR                                                 !3
         56        SEND_VAL                                                 7
         57        DO_ICALL                                         $32     
         58        ASSIGN                                                   !6, $32
   40    59        ISSET_ISEMPTY_CV                                 ~34     !6
         60        BOOL_NOT                                         ~35     ~34
         61      > JMPZ                                                     ~35, ->64
   41    62    >   CONCAT                                           ~36     '%23', !6
         63        ASSIGN_OP                                     8          !4, ~36
   45    64    >   CONCAT                                           ~38     !1, !4
         65        ASSIGN                                                   !7, ~38
   47    66        INIT_FCALL                                               'var_dump'
         67        SEND_VAR                                                 !1
         68        SEND_VAR                                                 !4
         69        DO_ICALL                                                 
   49    70      > RETURN                                                   !7
   51    71*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FXIQTN%3A16%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.27 ms | 1408 KiB | 21 Q