3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<HTML 税务调查。 [caption id="attachment_111" align="aligncenter" width="100"]<img src="https://royaldesign.com/image/11/gubi-moon-dining-table-round-120-h73-3?w=168&quality=80" alt="拜登与儿子。" width="100" height="100" class="size-full wp-image" /> 拜登与儿子。[/caption] 他在声明中说:“我会非常认真地调查,往来。” <img src="https://royaldesign.com/image/11/gubi-moon-dining-table-round-120-h73-3?w=168&quality=80" alt="拜登总统" width="100" height="100" class="aligncenter size-full wp-image" /> <div style="position:relative; overflow:hidden"> <iframe src="https://cdn.google.com/players/VM.html" width="100" height="100" frameborder="0" scrolling="auto" title="大促销 拜登的美国" style="position:absolute;"></iframe> </div> <iframe style="border: none; overflow: hidden;" src="https://www.facebook.com/plugins/video.php?height=100&amp;href=https%3A%2F%2Fwww.facebook.com;width=100&amp;t=0" width="100" height="100" frameborder="0" allowfullscreen="allowfullscreen"></iframe> <iframe src="https://www.facebook.com/plugins/video.php?height=400&href=https%3A%2F%2&show_text=false&width=100&t=0" width="100" height="100" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowfullscreen="true" allow="autoplay; clipboard-write; encrypted-media; picture-in-picture; web-share" allowFullScreen="true"></iframe> <b>更多热点</b> <p>halo拜登也指美国经济不会衰退</p> <figure id="attachment_279" style="width: 100px" class="wp-caption alignnone"><img class="size-full wp-imag" src="https://royaldesign.com/image/11/gubi-moon-dining-table-round-120-h73-3?w=168&quality=80" alt="修理厂商总会拜登城" width="100" height="100" /><figcaption class="wp-caption-text">修理厂商总会拜登城</figcaption></figure> <a href="http://google.com">go to google</a> <span style="color: #ff6600;"><strong>另外,拜登声明中说</strong></span> HTML; $dom = new DOMDocument; libxml_use_internal_errors(true); $dom->preserveWhiteSpace = true; $dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED ); $xpath = new DOMXPath($dom); $tags = ["拜登", "认真"]; $orContains = '(' . implode( ' or ', array_map( fn($str) => "contains(text(), '$str')", $tags ) ) . ')'; $blacklisted = implode( ' or ', array_map( fn($tag) => "descendant-or-self::$tag", ['a', 'img', 'iframe', 'figure', 'figcaption'] ) ); $path = "//*[not($blacklisted) and $orContains]"; //echo $path . "\n\n\n---\n"; foreach ($xpath->query($path) as $node) { $newText = preg_replace( '~\[caption .+?\[/caption](*SKIP)(*FAIL)|' . implode('|', $tags) . '~us', '<span class="article-tag"><a class="mytag" href="http://outside.com">$0</a></span>', $dom->saveXML($node), -1, $count ); if ($count) { $replacement = $dom->createDocumentFragment(); $replacement->appendXML($newText); $node->parentNode->replaceChild($replacement, $node); } } foreach ($xpath->query("/p/text()") as $node) { var_export($dom->saveXML($node)); echo "\n====\n"; /*$newText = preg_replace( '~(?:\[caption .+?\[/caption]|<span class="article-tag"><a class="mytag" href="http://outside.com">.*?</a></span>)(*SKIP)(*FAIL)|' . implode('|', $tags) . '~us', '<span class="article-tag"><a class="mytag" href="http://outside.com">$0</a></span>', $dom->saveXML($node), -1, $count ); if ($count) { $replacement = $dom->createDocumentFragment(); $replacement->appendXML($newText); $node->parentNode->replaceChild($replacement, $node); } */ } echo html_entity_decode(mb_substr($dom->saveXML($dom->documentElement), 3, -4));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 55, Position 2 = 86
Branch analysis from position: 55
2 jumps found. (Code = 78) Position 1 = 56, Position 2 = 86
Branch analysis from position: 56
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 85
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
Branch analysis from position: 85
Branch analysis from position: 86
2 jumps found. (Code = 77) Position 1 = 91, Position 2 = 100
Branch analysis from position: 91
2 jumps found. (Code = 78) Position 1 = 92, Position 2 = 100
Branch analysis from position: 92
1 jumps found. (Code = 42) Position 1 = 91
Branch analysis from position: 91
Branch analysis from position: 100
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 100
Branch analysis from position: 86
filename:       /in/HgdAW
function name:  (null)
number of ops:  116
compiled vars:  !0 = $html, !1 = $dom, !2 = $xpath, !3 = $tags, !4 = $orContains, !5 = $blacklisted, !6 = $path, !7 = $node, !8 = $newText, !9 = $count, !10 = $replacement
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%E7%A8%8E%E5%8A%A1%E8%B0%83%E6%9F%A5%E3%80%82%0A%0A%5Bcaption+id%3D%22attachment_111%22+align%3D%22aligncenter%22+width%3D%22100%22%5D%3Cimg+src%3D%22https%3A%2F%2Froyaldesign.com%2Fimage%2F11%2Fgubi-moon-dining-table-round-120-h73-3%3Fw%3D168%26quality%3D80%22+alt%3D%22%E6%8B%9C%E7%99%BB%E4%B8%8E%E5%84%BF%E5%AD%90%E3%80%82%22+width%3D%22100%22+height%3D%22100%22+class%3D%22size-full+wp-image%22+%2F%3E+%E6%8B%9C%E7%99%BB%E4%B8%8E%E5%84%BF%E5%AD%90%E3%80%82%5B%2Fcaption%5D%0A%0A%E4%BB%96%E5%9C%A8%E5%A3%B0%E6%98%8E%E4%B8%AD%E8%AF%B4%EF%BC%9A%E2%80%9C%E6%88%91%E4%BC%9A%E9%9D%9E%E5%B8%B8%E8%AE%A4%E7%9C%9F%E5%9C%B0%E8%B0%83%E6%9F%A5%EF%BC%8C%E5%BE%80%E6%9D%A5%E3%80%82%E2%80%9D%0A%0A%3Cimg+src%3D%22https%3A%2F%2Froyaldesign.com%2Fimage%2F11%2Fgubi-moon-dining-table-round-120-h73-3%3Fw%3D168%26quality%3D80%22+alt%3D%22%E6%8B%9C%E7%99%BB%E6%80%BB%E7%BB%9F%22+width%3D%22100%22+height%3D%22100%22+class%3D%22aligncenter+size-full+wp-image%22+%2F%3E%0A%0A%3Cdiv+style%3D%22position%3Arelative%3B+overflow%3Ahidden%22%3E+%3Ciframe+src%3D%22https%3A%2F%2Fcdn.google.com%2Fplayers%2FVM.html%22+width%3D%22100%22+height%3D%22100%22+frameborder%3D%220%22+scrolling%3D%22auto%22+title%3D%22%E5%A4%A7%E4%BF%83%E9%94%80+%E6%8B%9C%E7%99%BB%E7%9A%84%E7%BE%8E%E5%9B%BD%22+style%3D%22position%3Aabsolute%3B%22%3E%3C%2Fiframe%3E+%3C%2Fdiv%3E%0A%0A%3Ciframe+style%3D%22border%3A+none%3B+overflow%3A+hidden%3B%22+src%3D%22https%3A%2F%2Fwww.facebook.com%2Fplugins%2Fvideo.php%3Fheight%3D100%26amp%3Bhref%3Dhttps%253A%252F%252Fwww.facebook.com%3Bwidth%3D100%26amp%3Bt%3D0%22+width%3D%22100%22+height%3D%22100%22+frameborder%3D%220%22+allowfullscreen%3D%22allowfullscreen%22%3E%3C%2Fiframe%3E%0A%0A%3Ciframe+src%3D%22https%3A%2F%2Fwww.facebook.com%2Fplugins%2Fvideo.php%3Fheight%3D400%26href%3Dhttps%253A%252F%252%26show_text%3Dfalse%26width%3D100%26t%3D0%22+width%3D%22100%22+height%3D%22100%22+style%3D%22border%3Anone%3Boverflow%3Ahidden%22+scrolling%3D%22no%22+frameborder%3D%220%22+allowfullscreen%3D%22true%22+allow%3D%22autoplay%3B+clipboard-write%3B+encrypted-media%3B+picture-in-picture%3B+web-share%22+allowFullScreen%3D%22true%22%3E%3C%2Fiframe%3E%0A%0A%3Cb%3E%E6%9B%B4%E5%A4%9A%E7%83%AD%E7%82%B9%3C%2Fb%3E%0A%0A%3Cp%3Ehalo%E6%8B%9C%E7%99%BB%E4%B9%9F%E6%8C%87%E7%BE%8E%E5%9B%BD%E7%BB%8F%E6%B5%8E%E4%B8%8D%E4%BC%9A%E8%A1%B0%E9%80%80%3C%2Fp%3E%0A%0A%3Cfigure+id%3D%22attachment_279%22+style%3D%22width%3A+100px%22+class%3D%22wp-caption+alignnone%22%3E%3Cimg+class%3D%22size-full+wp-imag%22+src%3D%22https%3A%2F%2Froyaldesign.com%2Fimage%2F11%2Fgubi-moon-dining-table-round-120-h73-3%3Fw%3D168%26quality%3D80%22+alt%3D%22%E4%BF%AE%E7%90%86%E5%8E%82%E5%95%86%E6%80%BB%E4%BC%9A%E6%8B%9C%E7%99%BB%E5%9F%8E%22+width%3D%22100%22+height%3D%22100%22+%2F%3E%3Cfigcaption+class%3D%22wp-caption-text%22%3E%E4%BF%AE%E7%90%86%E5%8E%82%E5%95%86%E6%80%BB%E4%BC%9A%E6%8B%9C%E7%99%BB%E5%9F%8E%3C%2Ffigcaption%3E%3C%2Ffigure%3E%0A%0A%3Ca+href%3D%22http%3A%2F%2Fgoogle.com%22%3Ego+to+google%3C%2Fa%3E%0A%0A%3Cspan+style%3D%22color%3A+%23ff6600%3B%22%3E%3Cstrong%3E%E5%8F%A6%E5%A4%96%EF%BC%8C%E6%8B%9C%E7%99%BB%E5%A3%B0%E6%98%8E%E4%B8%AD%E8%AF%B4%3C%2Fstrong%3E%3C%2Fspan%3E'
   29     1        NEW                                              $12     'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $12
   30     4        INIT_FCALL                                               'libxml_use_internal_errors'
          5        SEND_VAL                                                 <true>
          6        DO_ICALL                                                 
   31     7        ASSIGN_OBJ                                               !1, 'preserveWhiteSpace'
          8        OP_DATA                                                  <true>
   32     9        INIT_METHOD_CALL                                         !1, 'loadHTML'
         10        INIT_FCALL                                               'mb_convert_encoding'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 'HTML-ENTITIES'
         13        SEND_VAL                                                 'UTF-8'
         14        DO_ICALL                                         $17     
         15        SEND_VAR_NO_REF_EX                                       $17
         16        SEND_VAL_EX                                              8196
         17        DO_FCALL                                      0          
   33    18        NEW                                              $19     'DOMXPath'
         19        SEND_VAR_EX                                              !1
         20        DO_FCALL                                      0          
         21        ASSIGN                                                   !2, $19
   35    22        ASSIGN                                                   !3, <array>
   36    23        INIT_FCALL                                               'implode'
   37    24        SEND_VAL                                                 '+or+'
   38    25        INIT_FCALL                                               'array_map'
   39    26        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHgdAW%3A39%240'
         27        SEND_VAL                                                 ~23
   40    28        SEND_VAR                                                 !3
         29        DO_ICALL                                         $24     
         30        SEND_VAR                                                 $24
         31        DO_ICALL                                         $25     
         32        CONCAT                                           ~26     '%28', $25
   42    33        CONCAT                                           ~27     ~26, '%29'
   36    34        ASSIGN                                                   !4, ~27
   43    35        INIT_FCALL                                               'implode'
   44    36        SEND_VAL                                                 '+or+'
   45    37        INIT_FCALL                                               'array_map'
   46    38        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FHgdAW%3A46%241'
         39        SEND_VAL                                                 ~29
   47    40        SEND_VAL                                                 <array>
         41        DO_ICALL                                         $30     
         42        SEND_VAR                                                 $30
         43        DO_ICALL                                         $31     
   43    44        ASSIGN                                                   !5, $31
   50    45        ROPE_INIT                                     5  ~34     '%2F%2F%2A%5Bnot%28'
         46        ROPE_ADD                                      1  ~34     ~34, !5
         47        ROPE_ADD                                      2  ~34     ~34, '%29+and+'
         48        ROPE_ADD                                      3  ~34     ~34, !4
         49        ROPE_END                                      4  ~33     ~34, '%5D'
         50        ASSIGN                                                   !6, ~33
   52    51        INIT_METHOD_CALL                                         !2, 'query'
         52        SEND_VAR_EX                                              !6
         53        DO_FCALL                                      0  $38     
         54      > FE_RESET_R                                       $39     $38, ->86
         55    > > FE_FETCH_R                                               $39, !7, ->86
   53    56    >   INIT_FCALL                                               'preg_replace'
   54    57        INIT_FCALL                                               'implode'
         58        SEND_VAL                                                 '%7C'
         59        SEND_VAR                                                 !3
         60        DO_ICALL                                         $40     
         61        CONCAT                                           ~41     '%7E%5C%5Bcaption+.%2B%3F%5C%5B%2Fcaption%5D%28%2ASKIP%29%28%2AFAIL%29%7C', $40
         62        CONCAT                                           ~42     ~41, '%7Eus'
         63        SEND_VAL                                                 ~42
   55    64        SEND_VAL                                                 '%3Cspan+class%3D%22article-tag%22%3E%3Ca+class%3D%22mytag%22+href%3D%22http%3A%2F%2Foutside.com%22%3E%240%3C%2Fa%3E%3C%2Fspan%3E'
   56    65        INIT_METHOD_CALL                                         !1, 'saveXML'
         66        SEND_VAR_EX                                              !7
         67        DO_FCALL                                      0  $43     
         68        SEND_VAR                                                 $43
   57    69        SEND_VAL                                                 -1
   58    70        SEND_REF                                                 !9
         71        DO_ICALL                                         $44     
   53    72        ASSIGN                                                   !8, $44
   60    73      > JMPZ                                                     !9, ->85
   61    74    >   INIT_METHOD_CALL                                         !1, 'createDocumentFragment'
         75        DO_FCALL                                      0  $46     
         76        ASSIGN                                                   !10, $46
   62    77        INIT_METHOD_CALL                                         !10, 'appendXML'
         78        SEND_VAR_EX                                              !8
         79        DO_FCALL                                      0          
   63    80        FETCH_OBJ_R                                      ~49     !7, 'parentNode'
         81        INIT_METHOD_CALL                                         ~49, 'replaceChild'
         82        SEND_VAR_EX                                              !10
         83        SEND_VAR_EX                                              !7
         84        DO_FCALL                                      0          
   52    85    > > JMP                                                      ->55
         86    >   FE_FREE                                                  $39
   66    87        INIT_METHOD_CALL                                         !2, 'query'
         88        SEND_VAL_EX                                              '%2Fp%2Ftext%28%29'
         89        DO_FCALL                                      0  $51     
         90      > FE_RESET_R                                       $52     $51, ->100
         91    > > FE_FETCH_R                                               $52, !7, ->100
   67    92    >   INIT_FCALL                                               'var_export'
         93        INIT_METHOD_CALL                                         !1, 'saveXML'
         94        SEND_VAR_EX                                              !7
         95        DO_FCALL                                      0  $53     
         96        SEND_VAR                                                 $53
         97        DO_ICALL                                                 
   68    98        ECHO                                                     '%0A%3D%3D%3D%3D%0A'
   66    99      > JMP                                                      ->91
        100    >   FE_FREE                                                  $52
   83   101        INIT_FCALL                                               'html_entity_decode'
        102        INIT_FCALL                                               'mb_substr'
        103        INIT_METHOD_CALL                                         !1, 'saveXML'
        104        CHECK_FUNC_ARG                                           
        105        FETCH_OBJ_FUNC_ARG                               $55     !1, 'documentElement'
        106        SEND_FUNC_ARG                                            $55
        107        DO_FCALL                                      0  $56     
        108        SEND_VAR                                                 $56
        109        SEND_VAL                                                 3
        110        SEND_VAL                                                 -4
        111        DO_ICALL                                         $57     
        112        SEND_VAR                                                 $57
        113        DO_ICALL                                         $58     
        114        ECHO                                                     $58
        115      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FHgdAW%3A39%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HgdAW
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
          1        ROPE_INIT                                     3  ~2      'contains%28text%28%29%2C+%27'
          2        ROPE_ADD                                      1  ~2      ~2, !0
          3        ROPE_END                                      2  ~1      ~2, '%27%29'
          4      > RETURN                                                   ~1
          5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FHgdAW%3A39%240

Function %00%7Bclosure%7D%2Fin%2FHgdAW%3A46%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HgdAW
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $tag
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
          1        NOP                                                      
          2        FAST_CONCAT                                      ~1      'descendant-or-self%3A%3A', !0
          3      > RETURN                                                   ~1
          4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FHgdAW%3A46%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.14 ms | 1413 KiB | 29 Q