3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = <<<TXT http://www.something.com and https://www.something.com</p> are working. Also http://www.something.com/some/thing/index.html works. www.something.com not and http://something.com. also gives a problem. Also https://something.com/something/else/test?something=true. This is a test for the URL thingy.This is a test for the URL thingy.This is.... etc.. TXT; if (preg_match_all('~(https?://|www)[a-z\d.-]+[\w/.?=&%:#]*\w~i', $text, $matches)) { foreach ($matches[0] as $url) { $prefix = stripos($url, 'www') === 0 ? 'http://' : ''; $text = str_replace($url, "<a href='{$prefix}{$url}'>{$url}</a>", $text); } } echo $text;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 34
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 33
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 33
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
Branch analysis from position: 34
filename:       /in/tS1DM
function name:  (null)
number of ops:  36
compiled vars:  !0 = $text, !1 = $matches, !2 = $url, !3 = $prefix
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'http%3A%2F%2Fwww.something.com+and+https%3A%2F%2Fwww.something.com%3C%2Fp%3E+are+working.+Also+http%3A%2F%2Fwww.something.com%2Fsome%2Fthing%2Findex.html+works.+%0A%0Awww.something.com+not+and+http%3A%2F%2Fsomething.com.+also+gives+a+problem.+Also+https%3A%2F%2Fsomething.com%2Fsomething%2Felse%2Ftest%3Fsomething%3Dtrue.+%0A%0AThis+is+a+test+for+the+URL+thingy.This+is+a+test+for+the+URL+thingy.This+is....+etc..'
   11     1        INIT_FCALL                                               'preg_match_all'
          2        SEND_VAL                                                 '%7E%28https%3F%3A%2F%2F%7Cwww%29%5Ba-z%5Cd.-%5D%2B%5B%5Cw%2F.%3F%3D%26%25%3A%23%5D%2A%5Cw%7Ei'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                         $5      
          6      > JMPZ                                                     $5, ->34
   12     7    >   FETCH_DIM_R                                      ~6      !1, 0
          8      > FE_RESET_R                                       $7      ~6, ->33
          9    > > FE_FETCH_R                                               $7, !2, ->33
   13    10    >   INIT_FCALL                                               'stripos'
         11        SEND_VAR                                                 !2
         12        SEND_VAL                                                 'www'
         13        DO_ICALL                                         $8      
         14        IS_IDENTICAL                                             $8, 0
         15      > JMPZ                                                     ~9, ->18
         16    >   QM_ASSIGN                                        ~10     'http%3A%2F%2F'
         17      > JMP                                                      ->19
         18    >   QM_ASSIGN                                        ~10     ''
         19    >   ASSIGN                                                   !3, ~10
   14    20        INIT_FCALL                                               'str_replace'
         21        SEND_VAR                                                 !2
         22        ROPE_INIT                                     6  ~13     '%3Ca+href%3D%27'
         23        ROPE_ADD                                      1  ~13     ~13, !3
         24        ROPE_ADD                                      2  ~13     ~13, !2
         25        ROPE_ADD                                      3  ~13     ~13, '%27%3E'
         26        ROPE_ADD                                      4  ~13     ~13, !2
         27        ROPE_END                                      5  ~12     ~13, '%3C%2Fa%3E'
         28        SEND_VAL                                                 ~12
         29        SEND_VAR                                                 !0
         30        DO_ICALL                                         $16     
         31        ASSIGN                                                   !0, $16
   12    32      > JMP                                                      ->9
         33    >   FE_FREE                                                  $7
   18    34    >   ECHO                                                     !0
   19    35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.58 ms | 1404 KiB | 19 Q