3v4l.org

run code in 300+ PHP versions simultaneously
<?php $content = <<<_HTML <!doctype html><html><head><title>What</title></head><body><p>(what)</p><div id="main"><p><span>what?</span></p><ul><li><span>foo</span> what!</li><li>(what?)</li></ul></div><p>(what)</p></body></html> _HTML; $find = ['(', ')', '?', '!']; $replace = ['(&#8202;', '&#8202;)', '&#8202;?', '&#8202;!']; $selector = implode(' or ', array_map(function($char) { return sprintf('contains(text(), "%s")', $char); }, $find)); $query = sprintf('//div[@id="main"]//*[%s]/text()', $selector); $doc = new DOMDocument(); $doc->loadHTML($content); $xpath = new DOMXPath($doc); $elements = $xpath->query($query); foreach ($elements as $element) { $element->nodeValue = html_entity_decode(str_replace($find, $replace, $element->nodeValue)); } echo $doc->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 33, Position 2 = 46
Branch analysis from position: 33
2 jumps found. (Code = 78) Position 1 = 34, Position 2 = 46
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
filename:       /in/Q0fsn
function name:  (null)
number of ops:  51
compiled vars:  !0 = $content, !1 = $find, !2 = $replace, !3 = $selector, !4 = $query, !5 = $doc, !6 = $xpath, !7 = $elements, !8 = $element
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3C%21doctype+html%3E%3Chtml%3E%3Chead%3E%3Ctitle%3EWhat%3C%2Ftitle%3E%3C%2Fhead%3E%3Cbody%3E%3Cp%3E%28what%29%3C%2Fp%3E%3Cdiv+id%3D%22main%22%3E%3Cp%3E%3Cspan%3Ewhat%3F%3C%2Fspan%3E%3C%2Fp%3E%3Cul%3E%3Cli%3E%3Cspan%3Efoo%3C%2Fspan%3E+what%21%3C%2Fli%3E%3Cli%3E%28what%3F%29%3C%2Fli%3E%3C%2Ful%3E%3C%2Fdiv%3E%3Cp%3E%28what%29%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E'
    7     1        ASSIGN                                                   !1, <array>
    8     2        ASSIGN                                                   !2, <array>
    9     3        INIT_FCALL                                               'implode'
          4        SEND_VAL                                                 '+or+'
          5        INIT_FCALL                                               'array_map'
          6        DECLARE_LAMBDA_FUNCTION                          ~12     [0]
   11     7        SEND_VAL                                                 ~12
          8        SEND_VAR                                                 !1
    9     9        DO_ICALL                                         $13     
   11    10        SEND_VAR                                                 $13
    9    11        DO_ICALL                                         $14     
         12        ASSIGN                                                   !3, $14
   13    13        INIT_FCALL                                               'sprintf'
         14        SEND_VAL                                                 '%2F%2Fdiv%5B%40id%3D%22main%22%5D%2F%2F%2A%5B%25s%5D%2Ftext%28%29'
         15        SEND_VAR                                                 !3
         16        DO_ICALL                                         $16     
         17        ASSIGN                                                   !4, $16
   15    18        NEW                                              $18     'DOMDocument'
         19        DO_FCALL                                      0          
         20        ASSIGN                                                   !5, $18
   16    21        INIT_METHOD_CALL                                         !5, 'loadHTML'
         22        SEND_VAR_EX                                              !0
         23        DO_FCALL                                      0          
   18    24        NEW                                              $22     'DOMXPath'
         25        SEND_VAR_EX                                              !5
         26        DO_FCALL                                      0          
         27        ASSIGN                                                   !6, $22
   19    28        INIT_METHOD_CALL                                         !6, 'query'
         29        SEND_VAR_EX                                              !4
         30        DO_FCALL                                      0  $25     
         31        ASSIGN                                                   !7, $25
   21    32      > FE_RESET_R                                       $27     !7, ->46
         33    > > FE_FETCH_R                                               $27, !8, ->46
   22    34    >   INIT_FCALL                                               'html_entity_decode'
         35        INIT_FCALL                                               'str_replace'
         36        SEND_VAR                                                 !1
         37        SEND_VAR                                                 !2
         38        FETCH_OBJ_R                                      ~29     !8, 'nodeValue'
         39        SEND_VAL                                                 ~29
         40        DO_ICALL                                         $30     
         41        SEND_VAR                                                 $30
         42        DO_ICALL                                         $31     
         43        ASSIGN_OBJ                                               !8, 'nodeValue'
         44        OP_DATA                                                  $31
   21    45      > JMP                                                      ->33
         46    >   FE_FREE                                                  $27
   25    47        INIT_METHOD_CALL                                         !5, 'saveHTML'
         48        DO_FCALL                                      0  $32     
         49        ECHO                                                     $32
         50      > 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/Q0fsn
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        INIT_FCALL                                               'sprintf'
          2        SEND_VAL                                                 'contains%28text%28%29%2C+%22%25s%22%29'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5      > RETURN                                                   $1
   11     6*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.32 ms | 1081 KiB | 18 Q