3v4l.org

run code in 500+ 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 = 49, Position 2 = 77
Branch analysis from position: 49
2 jumps found. (Code = 78) Position 1 = 50, Position 2 = 77
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 76
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 76
Branch analysis from position: 77
2 jumps found. (Code = 77) Position 1 = 82, Position 2 = 91
Branch analysis from position: 82
2 jumps found. (Code = 78) Position 1 = 83, Position 2 = 91
Branch analysis from position: 83
1 jumps found. (Code = 42) Position 1 = 82
Branch analysis from position: 82
Branch analysis from position: 91
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 91
Branch analysis from position: 77
filename:       /in/HgdAW
function name:  (null)
number of ops:  107
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>
   38    23        INIT_FCALL                                                   'array_map'
   39    24        DECLARE_LAMBDA_FUNCTION                              ~23     [0]
         25        SEND_VAL                                                     ~23
   40    26        SEND_VAR                                                     !3
   38    27        DO_ICALL                                             $24     
   36    28        FRAMELESS_ICALL_2                implode             ~25     '+or+', $24
   40    29        CONCAT                                               ~26     '%28', ~25
   42    30        CONCAT                                               ~27     ~26, '%29'
   36    31        ASSIGN                                                       !4, ~27
   45    32        INIT_FCALL                                                   'array_map'
   46    33        DECLARE_LAMBDA_FUNCTION                              ~29     [1]
         34        SEND_VAL                                                     ~29
   47    35        SEND_VAL                                                     <array>
   45    36        DO_ICALL                                             $30     
   43    37        FRAMELESS_ICALL_2                implode             ~31     '+or+', $30
         38        ASSIGN                                                       !5, ~31
   50    39        ROPE_INIT                                         5  ~34     '%2F%2F%2A%5Bnot%28'
         40        ROPE_ADD                                          1  ~34     ~34, !5
         41        ROPE_ADD                                          2  ~34     ~34, '%29+and+'
         42        ROPE_ADD                                          3  ~34     ~34, !4
         43        ROPE_END                                          4  ~33     ~34, '%5D'
         44        ASSIGN                                                       !6, ~33
   52    45        INIT_METHOD_CALL                                             !2, 'query'
         46        SEND_VAR_EX                                                  !6
         47        DO_FCALL                                          0  $38     
         48      > FE_RESET_R                                           $39     $38, ->77
         49    > > FE_FETCH_R                                                   $39, !7, ->77
   53    50    >   INIT_FCALL                                                   'preg_replace'
   54    51        FRAMELESS_ICALL_2                implode             ~40     '%7C', !3
         52        CONCAT                                               ~41     '%7E%5C%5Bcaption+.%2B%3F%5C%5B%2Fcaption%5D%28%2ASKIP%29%28%2AFAIL%29%7C', ~40
         53        CONCAT                                               ~42     ~41, '%7Eus'
         54        SEND_VAL                                                     ~42
   55    55        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    56        INIT_METHOD_CALL                                             !1, 'saveXML'
         57        SEND_VAR_EX                                                  !7
         58        DO_FCALL                                          0  $43     
         59        SEND_VAR                                                     $43
   57    60        SEND_VAL                                                     -1
   58    61        SEND_REF                                                     !9
   53    62        DO_ICALL                                             $44     
         63        ASSIGN                                                       !8, $44
   60    64      > JMPZ                                                         !9, ->76
   61    65    >   INIT_METHOD_CALL                                             !1, 'createDocumentFragment'
         66        DO_FCALL                                          0  $46     
         67        ASSIGN                                                       !10, $46
   62    68        INIT_METHOD_CALL                                             !10, 'appendXML'
         69        SEND_VAR_EX                                                  !8
         70        DO_FCALL                                          0          
   63    71        FETCH_OBJ_R                                          ~49     !7, 'parentNode'
         72        INIT_METHOD_CALL                                             ~49, 'replaceChild'
         73        SEND_VAR_EX                                                  !10
         74        SEND_VAR_EX                                                  !7
         75        DO_FCALL                                          0          
   52    76    > > JMP                                                          ->49
         77    >   FE_FREE                                                      $39
   66    78        INIT_METHOD_CALL                                             !2, 'query'
         79        SEND_VAL_EX                                                  '%2Fp%2Ftext%28%29'
         80        DO_FCALL                                          0  $51     
         81      > FE_RESET_R                                           $52     $51, ->91
         82    > > FE_FETCH_R                                                   $52, !7, ->91
   67    83    >   INIT_FCALL                                                   'var_export'
         84        INIT_METHOD_CALL                                             !1, 'saveXML'
         85        SEND_VAR_EX                                                  !7
         86        DO_FCALL                                          0  $53     
         87        SEND_VAR                                                     $53
         88        DO_ICALL                                                     
   68    89        ECHO                                                         '%0A%3D%3D%3D%3D%0A'
   66    90      > JMP                                                          ->82
         91    >   FE_FREE                                                      $52
   83    92        INIT_FCALL                                                   'html_entity_decode'
         93        INIT_FCALL                                                   'mb_substr'
         94        INIT_METHOD_CALL                                             !1, 'saveXML'
         95        CHECK_FUNC_ARG                                               
         96        FETCH_OBJ_FUNC_ARG                                   $55     !1, 'documentElement'
         97        SEND_FUNC_ARG                                                $55
         98        DO_FCALL                                          0  $56     
         99        SEND_VAR                                                     $56
        100        SEND_VAL                                                     3
        101        SEND_VAL                                                     -4
        102        DO_ICALL                                             $57     
        103        SEND_VAR                                                     $57
        104        DO_ICALL                                             $58     
        105        ECHO                                                         $58
        106      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HgdAW
function name:  {closure:/in/HgdAW:39}
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 Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/HgdAW
function name:  {closure:/in/HgdAW:46}
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 Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
180.76 ms | 2323 KiB | 20 Q