3v4l.org

run code in 300+ PHP versions simultaneously
<?php $re = '/(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$])/im'; $str = 'Test text http://hello-world.com Test text http://google.com/file.jpg?google=1 Test text https://hell.o.wor.ld/test?qwe=qwe Test text text text http://test.test/test hello all how are you I hope you all are fine '; $utmUrl = "utm_source=source&utm_medium=email&utm_campaign=mycamp"; $str = preg_replace_callback($re, function ($match) use ($utmUrl) { return $match[0] . (strpos($match[0], '?') !== false ? '&' : '?') . $utmUrl . ' '; }, $str); var_dump($str);
based on 5SepA
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/35csn
function name:  (null)
number of ops:  15
compiled vars:  !0 = $re, !1 = $str, !2 = $utmUrl
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   ASSIGN                                                   !0, '%2F%28%3F%3A%28%3F%3Ahttps%3F%7Cftp%7Cfile%29%3A%5C%2F%5C%2F%7Cwww%5C.%7Cftp%5C.%29%28%3F%3A%5C%28%5B-A-Z0-9%2B%26%40%23%5C%2F%25%3D%7E_%7C%24%3F%21%3A%2C.%5D%2A%5C%29%7C%5B-A-Z0-9%2B%26%40%23%5C%2F%25%3D%7E_%7C%24%3F%21%3A%2C.%5D%29%2A%28%3F%3A%5C%28%5B-A-Z0-9%2B%26%40%23%5C%2F%25%3D%7E_%7C%24%3F%21%3A%2C.%5D%2A%5C%29%7C%5BA-Z0-9%2B%26%40%23%5C%2F%25%3D%7E_%7C%24%5D%29%2Fim'
   4     1        ASSIGN                                                   !1, 'Test+text+http%3A%2F%2Fhello-world.com+Test+text++http%3A%2F%2Fgoogle.com%2Ffile.jpg%3Fgoogle%3D1+Test+text+https%3A%2F%2Fhell.o.wor.ld%2Ftest%3Fqwe%3Dqwe+Test+text+text+text+http%3A%2F%2Ftest.test%2Ftest+hello+all+how+are+you+I+hope+you+all+are+fine+'
   5     2        ASSIGN                                                   !2, 'utm_source%3Dsource%26utm_medium%3Demail%26utm_campaign%3Dmycamp'
   6     3        INIT_FCALL                                               'preg_replace_callback'
         4        SEND_VAR                                                 !0
         5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F35csn0x7f994107a273'
         6        BIND_LEXICAL                                             ~6, !2
   8     7        SEND_VAL                                                 ~6
         8        SEND_VAR                                                 !1
         9        DO_ICALL                                         $7      
        10        ASSIGN                                                   !1, $7
  10    11        INIT_FCALL                                               'var_dump'
        12        SEND_VAR                                                 !1
        13        DO_ICALL                                                 
        14      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F35csn0x7f994107a273:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/35csn
function name:  {closure}
number of ops:  18
compiled vars:  !0 = $match, !1 = $utmUrl
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   6     0  E >   RECV                                             !0      
         1        BIND_STATIC                                              !1
   7     2        FETCH_DIM_R                                      ~2      !0, 0
         3        INIT_FCALL                                               'strpos'
         4        FETCH_DIM_R                                      ~3      !0, 0
         5        SEND_VAL                                                 ~3
         6        SEND_VAL                                                 '%3F'
         7        DO_ICALL                                         $4      
         8        IS_EQUAL                                         ~5      $4, <false>
         9      > JMPZ                                                     ~5, ->12
        10    >   QM_ASSIGN                                        ~6      '%26'
        11      > JMP                                                      ->13
        12    >   QM_ASSIGN                                        ~6      '%3F'
        13    >   CONCAT                                           ~7      ~2, ~6
        14        CONCAT                                           ~8      ~7, !1
        15        CONCAT                                           ~9      ~8, '+'
        16      > RETURN                                                   ~9
   8    17*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F35csn0x7f994107a273

Generated using Vulcan Logic Dumper, using php 7.4.0