3v4l.org

run code in 500+ PHP versions simultaneously
<?php $string='<a blah href="http://example.com/readme.zip" blah2></a><img ><a blah href="http://example.com/readme.zqp" blah2></a>'; echo preg_replace('/(href="[^"]*\.(?!(?:zip|pdf|txt)")[^."]+")/', '$1 target="_blank"', $string) . "\n"; $doc = new DOMDocument(); $doc->loadHTML("<html>$string</html>", LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); foreach ($doc->getElementsByTagName('a') as $a) { $href = $a->getAttribute('href'); if (!preg_match('/(zip|pdf|txt)$/', $href)) { $a->setAttribute('target', '_blank'); } } echo substr($doc->saveHTML(), 6, -8);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 32
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 32
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 31
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 31
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/AEKTg
function name:  (null)
number of ops:  39
compiled vars:  !0 = $string, !1 = $doc, !2 = $a, !3 = $href
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%3Ca+blah+href%3D%22http%3A%2F%2Fexample.com%2Freadme.zip%22+blah2%3E%3C%2Fa%3E%3Cimg+%3E%3Ca+blah+href%3D%22http%3A%2F%2Fexample.com%2Freadme.zqp%22+blah2%3E%3C%2Fa%3E'
    4     1        FRAMELESS_ICALL_3                preg_replace        ~5      '%2F%28href%3D%22%5B%5E%22%5D%2A%5C.%28%3F%21%28%3F%3Azip%7Cpdf%7Ctxt%29%22%29%5B%5E.%22%5D%2B%22%29%2F', '%241+target%3D%22_blank%22'
          2        OP_DATA                                                      !0
          3        CONCAT                                               ~6      ~5, '%0A'
          4        ECHO                                                         ~6
    6     5        NEW                                                  $7      'DOMDocument'
          6        DO_FCALL                                          0          
          7        ASSIGN                                                       !1, $7
    7     8        INIT_METHOD_CALL                                             !1, 'loadHTML'
          9        ROPE_INIT                                         3  ~11     '%3Chtml%3E'
         10        ROPE_ADD                                          1  ~11     ~11, !0
         11        ROPE_END                                          2  ~10     ~11, '%3C%2Fhtml%3E'
         12        SEND_VAL_EX                                                  ~10
         13        SEND_VAL_EX                                                  8196
         14        DO_FCALL                                          0          
    8    15        INIT_METHOD_CALL                                             !1, 'getElementsByTagName'
         16        SEND_VAL_EX                                                  'a'
         17        DO_FCALL                                          0  $14     
         18      > FE_RESET_R                                           $15     $14, ->32
         19    > > FE_FETCH_R                                                   $15, !2, ->32
    9    20    >   INIT_METHOD_CALL                                             !2, 'getAttribute'
         21        SEND_VAL_EX                                                  'href'
         22        DO_FCALL                                          0  $16     
         23        ASSIGN                                                       !3, $16
   10    24        FRAMELESS_ICALL_2                preg_match          ~18     '%2F%28zip%7Cpdf%7Ctxt%29%24%2F', !3
         25        BOOL_NOT                                             ~19     ~18
         26      > JMPZ                                                         ~19, ->31
   11    27    >   INIT_METHOD_CALL                                             !2, 'setAttribute'
         28        SEND_VAL_EX                                                  'target'
         29        SEND_VAL_EX                                                  '_blank'
         30        DO_FCALL                                          0          
    8    31    > > JMP                                                          ->19
         32    >   FE_FREE                                                      $15
   14    33        INIT_METHOD_CALL                                             !1, 'saveHTML'
         34        DO_FCALL                                          0  $21     
         35        FRAMELESS_ICALL_3                substr              ~22     $21, 6
         36        OP_DATA                                                      -8
         37        ECHO                                                         ~22
         38      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
160.92 ms | 2342 KiB | 13 Q