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 = '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); $url = str_replace($baseUrl, '', $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($baseUrl, $path, $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/mgYRU
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, 'www.sape.ru'
   16     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FmgYRU%3A16%240'
          4        BIND_LEXICAL                                             ~7, !2
          5        ASSIGN                                                   !3, ~7
   56     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%2FmgYRU%3A16%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 61, Position 2 = 63
Branch analysis from position: 61
2 jumps found. (Code = 43) Position 1 = 71, Position 2 = 73
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 73
Branch analysis from position: 63
filename:       /in/mgYRU
function name:  {closure}
number of ops:  83
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
   26    36        INIT_FCALL                                               'str_replace'
         37        SEND_VAR                                                 !1
         38        SEND_VAL                                                 ''
         39        SEND_VAR                                                 !3
         40        DO_ICALL                                         $22     
         41        ASSIGN                                                   !3, $22
   28    42        INIT_FCALL                                               'preg_replace'
         43        SEND_VAL                                                 '%2F%5E%5B%5E%5C%2F%5D%5C%2F%2F'
         44        SEND_VAL                                                 '%2F'
         45        SEND_VAR                                                 !3
         46        DO_ICALL                                         $24     
         47        ASSIGN                                                   !3, $24
   31    48        INIT_FCALL                                               'parse_url'
         49        SEND_VAR                                                 !3
         50        SEND_VAL                                                 5
         51        DO_ICALL                                         $26     
         52        ASSIGN                                                   !4, $26
   36    53        INIT_FCALL                                               'parse_url'
         54        SEND_VAR                                                 !3
         55        SEND_VAL                                                 6
         56        DO_ICALL                                         $28     
         57        ASSIGN                                                   !5, $28
   37    58        ISSET_ISEMPTY_CV                                 ~30     !5
         59        BOOL_NOT                                         ~31     ~30
         60      > JMPZ                                                     ~31, ->63
   38    61    >   CONCAT                                           ~32     '%3F', !5
         62        ASSIGN_OP                                     8          !4, ~32
   42    63    >   INIT_FCALL                                               'parse_url'
         64        SEND_VAR                                                 !3
         65        SEND_VAL                                                 7
         66        DO_ICALL                                         $34     
         67        ASSIGN                                                   !6, $34
   43    68        ISSET_ISEMPTY_CV                                 ~36     !6
         69        BOOL_NOT                                         ~37     ~36
         70      > JMPZ                                                     ~37, ->73
   44    71    >   CONCAT                                           ~38     '%23', !6
         72        ASSIGN_OP                                     8          !4, ~38
   48    73    >   CONCAT                                           ~40     !1, '%2F'
         74        CONCAT                                           ~41     ~40, !4
         75        ASSIGN                                                   !7, ~41
   50    76        INIT_FCALL                                               'var_dump'
         77        SEND_VAR                                                 !1
         78        SEND_VAR                                                 !4
         79        SEND_VAR                                                 !7
         80        DO_ICALL                                                 
   52    81      > RETURN                                                   !7
   54    82*     > RETURN                                                   null

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.12 ms | 1404 KiB | 23 Q