3v4l.org

run code in 500+ 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 = 29, Position 2 = 39
Branch analysis from position: 29
2 jumps found. (Code = 78) Position 1 = 30, Position 2 = 39
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 39
filename:       /in/Q0fsn
function name:  (null)
number of ops:  44
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                                                   'array_map'
          4        DECLARE_LAMBDA_FUNCTION                              ~12     [0]
   11     5        SEND_VAL                                                     ~12
          6        SEND_VAR                                                     !1
    9     7        DO_ICALL                                             $13     
          8        FRAMELESS_ICALL_2                implode             ~14     '+or+', $13
          9        ASSIGN                                                       !3, ~14
   13    10        ROPE_INIT                                         3  ~17     '%2F%2Fdiv%5B%40id%3D%22main%22%5D%2F%2F%2A%5B'
         11        ROPE_ADD                                          1  ~17     ~17, !3
         12        ROPE_END                                          2  ~16     ~17, '%5D%2Ftext%28%29'
         13        ASSIGN                                                       !4, ~16
   15    14        NEW                                                  $20     'DOMDocument'
         15        DO_FCALL                                          0          
         16        ASSIGN                                                       !5, $20
   16    17        INIT_METHOD_CALL                                             !5, 'loadHTML'
         18        SEND_VAR_EX                                                  !0
         19        DO_FCALL                                          0          
   18    20        NEW                                                  $24     'DOMXPath'
         21        SEND_VAR_EX                                                  !5
         22        DO_FCALL                                          0          
         23        ASSIGN                                                       !6, $24
   19    24        INIT_METHOD_CALL                                             !6, 'query'
         25        SEND_VAR_EX                                                  !4
         26        DO_FCALL                                          0  $27     
         27        ASSIGN                                                       !7, $27
   21    28      > FE_RESET_R                                           $29     !7, ->39
         29    > > FE_FETCH_R                                                   $29, !8, ->39
   22    30    >   INIT_FCALL                                                   'html_entity_decode'
         31        FETCH_OBJ_R                                          ~31     !8, 'nodeValue'
         32        FRAMELESS_ICALL_3                str_replace         ~32     !1, !2
         33        OP_DATA                                                      ~31
         34        SEND_VAL                                                     ~32
         35        DO_ICALL                                             $33     
         36        ASSIGN_OBJ                                                   !8, 'nodeValue'
         37        OP_DATA                                                      $33
   21    38      > JMP                                                          ->29
         39    >   FE_FREE                                                      $29
   25    40        INIT_METHOD_CALL                                             !5, 'saveHTML'
         41        DO_FCALL                                          0  $34     
         42        ECHO                                                         $34
         43      > 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:/in/Q0fsn:9}
number of ops:  6
compiled vars:  !0 = $char
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   RECV                                                 !0      
   10     1        ROPE_INIT                                         3  ~2      'contains%28text%28%29%2C+%22'
          2        ROPE_ADD                                          1  ~2      ~2, !0
          3        ROPE_END                                          2  ~1      ~2, '%22%29'
          4      > RETURN                                                       ~1
   11     5*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
160.06 ms | 2198 KiB | 15 Q