3v4l.org

run code in 300+ PHP versions simultaneously
<?php function applyHLToSiblings(DOMDocument $D){ $words[0] = "cart"; /* $words[1] = "car"; $words[2] = "cartel"; $words[3] = "art"; $words[4] = "drug"; $words[5] = "drugs"; $words[6] = "rug"; $words[7] = "rugs"; */ $mt = function($content) use($D){ return $D->createTextNode($content); }; $ms = function($content = null, $name) use($D){ $span = $D->createElement("span"); $span->setAttribute("class", "word$name"); $content === null ?: $span->appendChild($content); return $span; }; $ps = function($siblingsContainer, $searchString, $name) use($D, $ms, $mt){ foreach($siblingsContainer->childNodes as $node){ if($node instanceof DOMText){ if(mb_strlen($node->textContent, "UTF-8") >= mb_strlen($searchString)){ $o = mb_strpos($node->textContent, $searchString); if($o !== false){ $l = mb_strlen($searchString, "UTF-8"); $before = mb_substr($node->textContent, 0, $o); $wrap = mb_substr($node->textContent, $o, $l); $after = mb_substr($node->textContent, $o + $l); $before = $ms($name, $wrap); $newSpan->textContent = $wrap; !$before ?: $node->insertBefore($node->nextSibling, $mt($before)); $node->insertBefore($node->nextSibling, $ms($mt($wrap), $name)); !$after ?: $node->insertBefore($node->nextSibling, $mt($after)); } } } } }; foreach($words as $name => $word) $ps($D->documentElement, $word, $name); } $x = new DOMDocument(); $x->loadXML("<data>drugs cartel</data>"); applyHLToSiblings($x); var_dump($x->saveXML());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0p40U
function name:  (null)
number of ops:  15
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   NEW                                              $1      'DOMDocument'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   59     3        INIT_METHOD_CALL                                         !0, 'loadXML'
          4        SEND_VAL_EX                                              '%3Cdata%3Edrugs+cartel%3C%2Fdata%3E'
          5        DO_FCALL                                      0          
   60     6        INIT_FCALL                                               'applyhltosiblings'
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0          
   61     9        INIT_FCALL                                               'var_dump'
         10        INIT_METHOD_CALL                                         !0, 'saveXML'
         11        DO_FCALL                                      0  $6      
         12        SEND_VAR                                                 $6
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Function applyhltosiblings:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 25
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 25
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/0p40U
function name:  applyHLToSiblings
number of ops:  27
compiled vars:  !0 = $D, !1 = $words, !2 = $mt, !3 = $ms, !4 = $ps, !5 = $word, !6 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN_DIM                                               !1, 0
          2        OP_DATA                                                  'cart'
   16     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F0p40U%3A16%240'
          4        BIND_LEXICAL                                             ~8, !0
          5        ASSIGN                                                   !2, ~8
   20     6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F0p40U%3A20%241'
          7        BIND_LEXICAL                                             ~10, !0
          8        ASSIGN                                                   !3, ~10
   27     9        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F0p40U%3A27%242'
         10        BIND_LEXICAL                                             ~12, !0
         11        BIND_LEXICAL                                             ~12, !3
         12        BIND_LEXICAL                                             ~12, !2
         13        ASSIGN                                                   !4, ~12
   51    14      > FE_RESET_R                                       $14     !1, ->25
         15    > > FE_FETCH_R                                       ~15     $14, !5, ->25
         16    >   ASSIGN                                                   !6, ~15
   52    17        INIT_DYNAMIC_CALL                                        !4
         18        CHECK_FUNC_ARG                                           
         19        FETCH_OBJ_FUNC_ARG                               $17     !0, 'documentElement'
         20        SEND_FUNC_ARG                                            $17
         21        SEND_VAR_EX                                              !5
         22        SEND_VAR_EX                                              !6
         23        DO_FCALL                                      0          
   51    24      > JMP                                                      ->15
         25    >   FE_FREE                                                  $14
   55    26      > RETURN                                                   null

End of function applyhltosiblings

Function %00%7Bclosure%7D%2Fin%2F0p40U%3A16%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0p40U
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $content, !1 = $D
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   17     2        INIT_METHOD_CALL                                         !1, 'createTextNode'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5      > RETURN                                                   $2
   18     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F0p40U%3A16%240

Function %00%7Bclosure%7D%2Fin%2F0p40U%3A20%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0p40U
function name:  {closure}
number of ops:  22
compiled vars:  !0 = $content, !1 = $name, !2 = $D, !3 = $span
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV_INIT                                        !0      null
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   21     3        INIT_METHOD_CALL                                         !2, 'createElement'
          4        SEND_VAL_EX                                              'span'
          5        DO_FCALL                                      0  $4      
          6        ASSIGN                                                   !3, $4
   22     7        INIT_METHOD_CALL                                         !3, 'setAttribute'
          8        SEND_VAL_EX                                              'class'
          9        NOP                                                      
         10        FAST_CONCAT                                      ~6      'word', !1
         11        SEND_VAL_EX                                              ~6
         12        DO_FCALL                                      0          
   23    13        TYPE_CHECK                                    2  ~8      !0
         14        JMP_SET                                          ~9      ~8, ->19
         15        INIT_METHOD_CALL                                         !3, 'appendChild'
         16        SEND_VAR_EX                                              !0
         17        DO_FCALL                                      0  $10     
         18        QM_ASSIGN                                        ~9      $10
         19        FREE                                                     ~9
   24    20      > RETURN                                                   !3
   25    21*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F0p40U%3A20%241

Function %00%7Bclosure%7D%2Fin%2F0p40U%3A27%242:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 102
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 102
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 101
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 101
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 101
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 101
Branch analysis from position: 101
Branch analysis from position: 101
Branch analysis from position: 102
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 102
filename:       /in/0p40U
function name:  {closure}
number of ops:  104
compiled vars:  !0 = $siblingsContainer, !1 = $searchString, !2 = $name, !3 = $D, !4 = $ms, !5 = $mt, !6 = $node, !7 = $o, !8 = $l, !9 = $before, !10 = $wrap, !11 = $after, !12 = $newSpan
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        BIND_STATIC                                              !3
          4        BIND_STATIC                                              !4
          5        BIND_STATIC                                              !5
   28     6        FETCH_OBJ_R                                      ~13     !0, 'childNodes'
          7      > FE_RESET_R                                       $14     ~13, ->102
          8    > > FE_FETCH_R                                               $14, !6, ->102
   29     9    >   INSTANCEOF                                               !6, 'DOMText'
         10      > JMPZ                                                     ~15, ->101
   30    11    >   INIT_FCALL                                               'mb_strlen'
         12        FETCH_OBJ_R                                      ~16     !6, 'textContent'
         13        SEND_VAL                                                 ~16
         14        SEND_VAL                                                 'UTF-8'
         15        DO_ICALL                                         $17     
         16        INIT_FCALL                                               'mb_strlen'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $18     
         19        IS_SMALLER_OR_EQUAL                                      $18, $17
         20      > JMPZ                                                     ~19, ->101
   31    21    >   INIT_FCALL                                               'mb_strpos'
         22        FETCH_OBJ_R                                      ~20     !6, 'textContent'
         23        SEND_VAL                                                 ~20
         24        SEND_VAR                                                 !1
         25        DO_ICALL                                         $21     
         26        ASSIGN                                                   !7, $21
   32    27        TYPE_CHECK                                  1018          !7
         28      > JMPZ                                                     ~23, ->101
   33    29    >   INIT_FCALL                                               'mb_strlen'
         30        SEND_VAR                                                 !1
         31        SEND_VAL                                                 'UTF-8'
         32        DO_ICALL                                         $24     
         33        ASSIGN                                                   !8, $24
   34    34        INIT_FCALL                                               'mb_substr'
         35        FETCH_OBJ_R                                      ~26     !6, 'textContent'
         36        SEND_VAL                                                 ~26
         37        SEND_VAL                                                 0
         38        SEND_VAR                                                 !7
         39        DO_ICALL                                         $27     
         40        ASSIGN                                                   !9, $27
   35    41        INIT_FCALL                                               'mb_substr'
         42        FETCH_OBJ_R                                      ~29     !6, 'textContent'
         43        SEND_VAL                                                 ~29
         44        SEND_VAR                                                 !7
         45        SEND_VAR                                                 !8
         46        DO_ICALL                                         $30     
         47        ASSIGN                                                   !10, $30
   36    48        INIT_FCALL                                               'mb_substr'
         49        FETCH_OBJ_R                                      ~32     !6, 'textContent'
         50        SEND_VAL                                                 ~32
         51        ADD                                              ~33     !7, !8
         52        SEND_VAL                                                 ~33
         53        DO_ICALL                                         $34     
         54        ASSIGN                                                   !11, $34
   38    55        INIT_DYNAMIC_CALL                                        !4
         56        SEND_VAR_EX                                              !2
         57        SEND_VAR_EX                                              !10
         58        DO_FCALL                                      0  $36     
         59        ASSIGN                                                   !9, $36
   39    60        ASSIGN_OBJ                                               !12, 'textContent'
         61        OP_DATA                                                  !10
   41    62        BOOL_NOT                                         ~39     !9
         63        JMP_SET                                          ~40     ~39, ->74
         64        INIT_METHOD_CALL                                         !6, 'insertBefore'
         65        CHECK_FUNC_ARG                                           
         66        FETCH_OBJ_FUNC_ARG                               $41     !6, 'nextSibling'
         67        SEND_FUNC_ARG                                            $41
         68        INIT_DYNAMIC_CALL                                        !5
         69        SEND_VAR_EX                                              !9
         70        DO_FCALL                                      0  $42     
         71        SEND_VAR_NO_REF_EX                                       $42
         72        DO_FCALL                                      0  $43     
         73        QM_ASSIGN                                        ~40     $43
         74        FREE                                                     ~40
   42    75        INIT_METHOD_CALL                                         !6, 'insertBefore'
         76        CHECK_FUNC_ARG                                           
         77        FETCH_OBJ_FUNC_ARG                               $44     !6, 'nextSibling'
         78        SEND_FUNC_ARG                                            $44
         79        INIT_DYNAMIC_CALL                                        !4
         80        INIT_DYNAMIC_CALL                                        !5
         81        SEND_VAR_EX                                              !10
         82        DO_FCALL                                      0  $45     
         83        SEND_VAR_NO_REF_EX                                       $45
         84        SEND_VAR_EX                                              !2
         85        DO_FCALL                                      0  $46     
         86        SEND_VAR_NO_REF_EX                                       $46
         87        DO_FCALL                                      0          
   43    88        BOOL_NOT                                         ~48     !11
         89        JMP_SET                                          ~49     ~48, ->100
         90        INIT_METHOD_CALL                                         !6, 'insertBefore'
         91        CHECK_FUNC_ARG                                           
         92        FETCH_OBJ_FUNC_ARG                               $50     !6, 'nextSibling'
         93        SEND_FUNC_ARG                                            $50
         94        INIT_DYNAMIC_CALL                                        !5
         95        SEND_VAR_EX                                              !11
         96        DO_FCALL                                      0  $51     
         97        SEND_VAR_NO_REF_EX                                       $51
         98        DO_FCALL                                      0  $52     
         99        QM_ASSIGN                                        ~49     $52
        100        FREE                                                     ~49
   28   101    > > JMP                                                      ->8
        102    >   FE_FREE                                                  $14
   49   103      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F0p40U%3A27%242

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.24 ms | 1415 KiB | 22 Q