3v4l.org

run code in 500+ PHP versions simultaneously
<?php $html = 'This should be extracted <p>I do not want this</p> This should also be extracted <a>This may appear after other tags and I do not want this</a>'; $doc = new DOMDocument(); $doc->loadHTML("<div>$html</div>", LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); $xpath = new DOMXPath($doc); $texts = array(); foreach ($xpath->query('/div/text()') as $text) { $texts[] = $text->nodeValue; } print_r($texts);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 25
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/gHEYr
function name:  (null)
number of ops:  30
compiled vars:  !0 = $html, !1 = $doc, !2 = $xpath, !3 = $texts, !4 = $text
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, 'This+should+be+extracted+%3Cp%3EI+do+not+want+this%3C%2Fp%3E+This+should+also+be+extracted+%3Ca%3EThis+may+appear+after+other+tags+and+I+do+not+want+this%3C%2Fa%3E'
    4     1        NEW                                                  $6      'DOMDocument'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !1, $6
    5     4        INIT_METHOD_CALL                                             !1, 'loadHTML'
          5        ROPE_INIT                                         3  ~10     '%3Cdiv%3E'
          6        ROPE_ADD                                          1  ~10     ~10, !0
          7        ROPE_END                                          2  ~9      ~10, '%3C%2Fdiv%3E'
          8        SEND_VAL_EX                                                  ~9
          9        SEND_VAL_EX                                                  8196
         10        DO_FCALL                                          0          
    6    11        NEW                                                  $13     'DOMXPath'
         12        SEND_VAR_EX                                                  !1
         13        DO_FCALL                                          0          
         14        ASSIGN                                                       !2, $13
    7    15        ASSIGN                                                       !3, <array>
    8    16        INIT_METHOD_CALL                                             !2, 'query'
         17        SEND_VAL_EX                                                  '%2Fdiv%2Ftext%28%29'
         18        DO_FCALL                                          0  $17     
         19      > FE_RESET_R                                           $18     $17, ->25
         20    > > FE_FETCH_R                                                   $18, !4, ->25
    9    21    >   FETCH_OBJ_R                                          ~20     !4, 'nodeValue'
         22        ASSIGN_DIM                                                   !3
         23        OP_DATA                                                      ~20
    8    24      > JMP                                                          ->20
         25    >   FE_FREE                                                      $18
   11    26        INIT_FCALL                                                   'print_r'
         27        SEND_VAR                                                     !3
         28        DO_ICALL                                                     
         29      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
161.43 ms | 2608 KiB | 14 Q