3v4l.org

run code in 500+ PHP versions simultaneously
<?php $result = <<<HTML <a href="SOME_URL"> <a href="SOME_URL_2"> </a> </a> <a href="SOME_URL3"> <a href="SOME_URL_4"> </a> </a> <a href="SOME_URL_5"> </a> <a href="SOME_URL_6"> </a> HTML; $dom = new DOMDocument(); @$dom->loadHTML($result); foreach($dom->getElementsByTagName('a') as $link) { $tag_html = $dom->saveHTML($link); //Get tag inner html if (substr_count($tag_html, "href") > 1) { //If tag contains more than one href attribute preg_match_all('/href="([^"]*)"/is', $tag_html, $link_output, PREG_SET_ORDER); $output[] = $link_output[1][1]; //Output second href } else { //Not nested tag $output[] = $link->getAttribute('href'); //Output first href } } echo "<pre>"; print_r($output); echo "</pre>";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 41
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 41
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 35
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
filename:       /in/NjYF2
function name:  (null)
number of ops:  48
compiled vars:  !0 = $result, !1 = $dom, !2 = $link, !3 = $tag_html, !4 = $link_output, !5 = $output
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%3Ca+href%3D%22SOME_URL%22%3E%0A++++%3Ca+href%3D%22SOME_URL_2%22%3E%0A++++%3C%2Fa%3E%0A%3C%2Fa%3E%0A%0A%3Ca+href%3D%22SOME_URL3%22%3E%0A++++%3Ca+href%3D%22SOME_URL_4%22%3E%0A++++%3C%2Fa%3E%0A%3C%2Fa%3E%0A%0A%3Ca+href%3D%22SOME_URL_5%22%3E%0A%3C%2Fa%3E%0A%3Ca+href%3D%22SOME_URL_6%22%3E%0A%3C%2Fa%3E%0A'
   21     1        NEW                                                  $7      'DOMDocument'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !1, $7
   22     4        BEGIN_SILENCE                                        ~10     
          5        INIT_METHOD_CALL                                             !1, 'loadHTML'
          6        SEND_VAR_EX                                                  !0
          7        DO_FCALL                                          0          
          8        END_SILENCE                                                  ~10
   25     9        INIT_METHOD_CALL                                             !1, 'getElementsByTagName'
         10        SEND_VAL_EX                                                  'a'
         11        DO_FCALL                                          0  $12     
         12      > FE_RESET_R                                           $13     $12, ->41
         13    > > FE_FETCH_R                                                   $13, !2, ->41
   27    14    >   INIT_METHOD_CALL                                             !1, 'saveHTML'
         15        SEND_VAR_EX                                                  !2
         16        DO_FCALL                                          0  $14     
         17        ASSIGN                                                       !3, $14
   29    18        INIT_FCALL                                                   'substr_count'
         19        SEND_VAR                                                     !3
         20        SEND_VAL                                                     'href'
         21        DO_ICALL                                             $16     
         22        IS_SMALLER                                                   1, $16
         23      > JMPZ                                                         ~17, ->35
   30    24    >   INIT_FCALL                                                   'preg_match_all'
         25        SEND_VAL                                                     '%2Fhref%3D%22%28%5B%5E%22%5D%2A%29%22%2Fis'
         26        SEND_VAR                                                     !3
         27        SEND_REF                                                     !4
         28        SEND_VAL                                                     2
         29        DO_ICALL                                                     
   31    30        FETCH_DIM_R                                          ~20     !4, 1
         31        FETCH_DIM_R                                          ~21     ~20, 1
         32        ASSIGN_DIM                                                   !5
         33        OP_DATA                                                      ~21
   29    34      > JMP                                                          ->40
   33    35    >   INIT_METHOD_CALL                                             !2, 'getAttribute'
         36        SEND_VAL_EX                                                  'href'
         37        DO_FCALL                                          0  $23     
         38        ASSIGN_DIM                                                   !5
         39        OP_DATA                                                      $23
   25    40    > > JMP                                                          ->13
         41    >   FE_FREE                                                      $13
   37    42        ECHO                                                         '%3Cpre%3E'
   38    43        INIT_FCALL                                                   'print_r'
         44        SEND_VAR                                                     !5
         45        DO_ICALL                                                     
   39    46        ECHO                                                         '%3C%2Fpre%3E'
         47      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
157.95 ms | 1610 KiB | 16 Q