3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html=<<<HTML <a href="bla">123 "this" is asd</a> <a href="bla">this should not be captured</a> <a href="bla">no quotes in anchor text here</a> <a href="bla">"445 is in quotes"</a> <a href="bla">asd "blabla" sometimes</a> <a href="bla">Je commence à avoir mal à la tête</a> <a href="bla">something with quotes like “blabla” is bad</a> HTML; $dom = new DOMDocument; $html=mb_convert_encoding($html,'HTML-ENTITIES',"UTF-8"); $dom->loadHTML($html,LIBXML_HTML_NODEFDTD); // 2nd params to remove DOCTYPE); foreach($dom->getElementsByTagName('a') as $a){ //echo $a->nodeValue,"\n"; if(preg_match('~["“”]~u',$a->nodeValue)){ $remove[]=$a; } } foreach($remove as $bad_a){ $bad_a->parentNode->removeChild($bad_a); } $result=mb_convert_encoding($dom->saveHTML(),"UTF-8",'HTML-ENTITIES'); echo preg_replace(['~^<html><body>|</body></html>$~','~\R+~'],['',"\n"],$result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 28
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 28
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 27
Branch analysis from position: 28
2 jumps found. (Code = 77) Position 1 = 30, Position 2 = 36
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 36
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
Branch analysis from position: 28
filename:       /in/kXlLb
function name:  (null)
number of ops:  52
compiled vars:  !0 = $html, !1 = $dom, !2 = $a, !3 = $remove, !4 = $bad_a, !5 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%3Ca+href%3D%22bla%22%3E123+%22this%22+is+asd%3C%2Fa%3E%0A%3Ca+href%3D%22bla%22%3Ethis+should+not+be+captured%3C%2Fa%3E%0A%3Ca+href%3D%22bla%22%3Eno+quotes+in+anchor+text+here%3C%2Fa%3E%0A%3Ca+href%3D%22bla%22%3E%22445+is+in+quotes%22%3C%2Fa%3E%0A%3Ca+href%3D%22bla%22%3Easd+%22blabla%22+sometimes%3C%2Fa%3E%0A%3Ca+href%3D%22bla%22%3EJe+commence+%C3%A0+avoir+mal+%C3%A0+la+t%C3%AAte%3C%2Fa%3E%0A%3Ca+href%3D%22bla%22%3Esomething+with+quotes+like+%E2%80%9Cblabla%E2%80%9D+is+bad%3C%2Fa%3E'
   12     1        NEW                                              $7      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $7
   13     4        INIT_FCALL                                               'mb_convert_encoding'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 'HTML-ENTITIES'
          7        SEND_VAL                                                 'UTF-8'
          8        DO_ICALL                                         $10     
          9        ASSIGN                                                   !0, $10
   14    10        INIT_METHOD_CALL                                         !1, 'loadHTML'
         11        SEND_VAR_EX                                              !0
         12        SEND_VAL_EX                                              4
         13        DO_FCALL                                      0          
   15    14        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
         15        SEND_VAL_EX                                              'a'
         16        DO_FCALL                                      0  $13     
         17      > FE_RESET_R                                       $14     $13, ->28
         18    > > FE_FETCH_R                                               $14, !2, ->28
   17    19    >   INIT_FCALL                                               'preg_match'
         20        SEND_VAL                                                 '%7E%5B%22%E2%80%9C%E2%80%9D%5D%7Eu'
         21        FETCH_OBJ_R                                      ~15     !2, 'nodeValue'
         22        SEND_VAL                                                 ~15
         23        DO_ICALL                                         $16     
         24      > JMPZ                                                     $16, ->27
   18    25    >   ASSIGN_DIM                                               !3
         26        OP_DATA                                                  !2
   15    27    > > JMP                                                      ->18
         28    >   FE_FREE                                                  $14
   21    29      > FE_RESET_R                                       $18     !3, ->36
         30    > > FE_FETCH_R                                               $18, !4, ->36
   22    31    >   FETCH_OBJ_R                                      ~19     !4, 'parentNode'
         32        INIT_METHOD_CALL                                         ~19, 'removeChild'
         33        SEND_VAR_EX                                              !4
         34        DO_FCALL                                      0          
   21    35      > JMP                                                      ->30
         36    >   FE_FREE                                                  $18
   24    37        INIT_FCALL                                               'mb_convert_encoding'
         38        INIT_METHOD_CALL                                         !1, 'saveHTML'
         39        DO_FCALL                                      0  $21     
         40        SEND_VAR                                                 $21
         41        SEND_VAL                                                 'UTF-8'
         42        SEND_VAL                                                 'HTML-ENTITIES'
         43        DO_ICALL                                         $22     
         44        ASSIGN                                                   !5, $22
   25    45        INIT_FCALL                                               'preg_replace'
         46        SEND_VAL                                                 <array>
         47        SEND_VAL                                                 <array>
         48        SEND_VAR                                                 !5
         49        DO_ICALL                                         $24     
         50        ECHO                                                     $24
         51      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.97 ms | 1400 KiB | 19 Q