3v4l.org

run code in 500+ PHP versions simultaneously
<?php $main = '<div class="post-inner"><div class="entry"><p><strong><a href="http://example.net">link</a></strong></p></div></div>'; $doc = new DOMDocument(); $doc->loadHTML($main, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $xpath = new DOMXpath($doc); $anchors = $xpath->query('//div[contains(@class, "post-inner")]//a'); foreach ($anchors as $a) { $a->setAttribute('href', 'https://shortdomain.com/api?p=' . $a->attributes->getNamedItem('href')->nodeValue); } echo $doc->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 29
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 29
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/ubr5s
function name:  (null)
number of ops:  34
compiled vars:  !0 = $main, !1 = $doc, !2 = $xpath, !3 = $anchors, !4 = $a
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, '%3Cdiv+class%3D%22post-inner%22%3E%3Cdiv+class%3D%22entry%22%3E%3Cp%3E%3Cstrong%3E%3Ca+href%3D%22http%3A%2F%2Fexample.net%22%3Elink%3C%2Fa%3E%3C%2Fstrong%3E%3C%2Fp%3E%3C%2Fdiv%3E%3C%2Fdiv%3E'
    3     1        NEW                                                  $6      'DOMDocument'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !1, $6
    4     4        INIT_METHOD_CALL                                             !1, 'loadHTML'
          5        SEND_VAR_EX                                                  !0
          6        SEND_VAL_EX                                                  8196
          7        DO_FCALL                                          0          
    5     8        NEW                                                  $10     'DOMXpath'
          9        SEND_VAR_EX                                                  !1
         10        DO_FCALL                                          0          
         11        ASSIGN                                                       !2, $10
    6    12        INIT_METHOD_CALL                                             !2, 'query'
         13        SEND_VAL_EX                                                  '%2F%2Fdiv%5Bcontains%28%40class%2C+%22post-inner%22%29%5D%2F%2Fa'
         14        DO_FCALL                                          0  $13     
         15        ASSIGN                                                       !3, $13
    7    16      > FE_RESET_R                                           $15     !3, ->29
         17    > > FE_FETCH_R                                                   $15, !4, ->29
    8    18    >   INIT_METHOD_CALL                                             !4, 'setAttribute'
         19        SEND_VAL_EX                                                  'href'
         20        FETCH_OBJ_R                                          ~16     !4, 'attributes'
         21        INIT_METHOD_CALL                                             ~16, 'getNamedItem'
         22        SEND_VAL_EX                                                  'href'
         23        DO_FCALL                                          0  $17     
         24        FETCH_OBJ_R                                          ~18     $17, 'nodeValue'
         25        CONCAT                                               ~19     'https%3A%2F%2Fshortdomain.com%2Fapi%3Fp%3D', ~18
         26        SEND_VAL_EX                                                  ~19
         27        DO_FCALL                                          0          
    7    28      > JMP                                                          ->17
         29    >   FE_FREE                                                      $15
   10    30        INIT_METHOD_CALL                                             !1, 'saveHTML'
         31        DO_FCALL                                          0  $21     
         32        ECHO                                                         $21
         33      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
164.54 ms | 2573 KiB | 13 Q