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); $after ? $node->parentNode->insertBefore($mt($after) , $node->nextSibling) : null; $node->parentNode->insertBefore($ms($mt($wrap), $name) , $node->nextSibling); $before ? $node->parentNode->insertBefore($mt($before) , $node->nextSibling) : null; $node->parentNode->removeChild($node); } } } } }; 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/OOE7Q
function name:  (null)
number of ops:  15
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   NEW                                              $1      'DOMDocument'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   57     3        INIT_METHOD_CALL                                         !0, 'loadXML'
          4        SEND_VAL_EX                                              '%3Cdata%3Edrugs+cartel%3C%2Fdata%3E'
          5        DO_FCALL                                      0          
   58     6        INIT_FCALL                                               'applyhltosiblings'
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0          
   59     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/OOE7Q
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%2FOOE7Q%3A16%240'
          4        BIND_LEXICAL                                             ~8, !0
          5        ASSIGN                                                   !2, ~8
   20     6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FOOE7Q%3A20%241'
          7        BIND_LEXICAL                                             ~10, !0
          8        ASSIGN                                                   !3, ~10
   27     9        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FOOE7Q%3A27%242'
         10        BIND_LEXICAL                                             ~12, !0
         11        BIND_LEXICAL                                             ~12, !3
         12        BIND_LEXICAL                                             ~12, !2
         13        ASSIGN                                                   !4, ~12
   49    14      > FE_RESET_R                                       $14     !1, ->25
         15    > > FE_FETCH_R                                       ~15     $14, !5, ->25
         16    >   ASSIGN                                                   !6, ~15
   50    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          
   49    24      > JMP                                                      ->15
         25    >   FE_FREE                                                  $14
   53    26      > RETURN                                                   null

End of function applyhltosiblings

Function %00%7Bclosure%7D%2Fin%2FOOE7Q%3A16%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OOE7Q
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%2FOOE7Q%3A16%240

Function %00%7Bclosure%7D%2Fin%2FOOE7Q%3A20%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OOE7Q
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%2FOOE7Q%3A20%241

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

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
205.41 ms | 1415 KiB | 22 Q