3v4l.org

run code in 300+ PHP versions simultaneously
<?php $content = "λ"; $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->encoding = "UTF-8"; $dom->strictErrorChecking = false; $dom->substituteEntities = false; $dom->formatOutput = false; mb_detect_order("ASCII,UTF-8,ISO-8859-1,windows-1252,iso-8859-15"); function loadNprepare($content,$encod='') { if (!empty($content)) { if (empty($encod)) $encod = mb_detect_encoding($content); $headpos = mb_strpos($content,'<head>'); if (FALSE=== $headpos) $headpos= mb_strpos($content,'<HEAD>'); if (FALSE!== $headpos) { $headpos+=6; $content = mb_substr($content,0,$headpos) . '<meta http-equiv="Content-Type" content="text/html; charset='.$encod.'">' .mb_substr($content,$headpos); } $content=mb_convert_encoding($content, 'HTML-ENTITIES', $encod); } return $content; } // Little hack to force UTF-8 // if (strpos($content, '<?xml encoding') === false) { // $hack = strpos($content, '<body') === false ? '<?xml encoding="UTF-8"><meta http-equiv="content-type" content="text/html; charset=UTF-8"><body>' : '<?xml encoding="UTF-8">'; // $loaded = $dom->loadHTML($hack . $content); // } else { // $loaded = $dom->loadHTML($content); // } $dom->loadHTML(loadNprepare($content)); foreach ($dom->childNodes as $item) { if ($item->nodeType === XML_PI_NODE) { $dom->removeChild($item); // remove encoding hack break; } } // Remove added body & doctype $exportedContent = preg_replace(array( "/^\<\!DOCTYPE.*?<html><body>/si", "!</body></html>$!si"), "", $dom->saveHTML()); var_dump(trim($exportedContent)); // Should return string(8) "&lambda;"
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 34
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 34
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 33
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 34
Branch analysis from position: 34
filename:       /in/HnhdC
function name:  (null)
number of ops:  50
compiled vars:  !0 = $content, !1 = $dom, !2 = $item, !3 = $exportedContent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%CE%BB'
    5     1        NEW                                              $5      'DOMDocument'
          2        SEND_VAL_EX                                              '1.0'
          3        SEND_VAL_EX                                              'UTF-8'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
    6     6        ASSIGN_OBJ                                               !1, 'encoding'
          7        OP_DATA                                                  'UTF-8'
    8     8        ASSIGN_OBJ                                               !1, 'strictErrorChecking'
          9        OP_DATA                                                  <false>
    9    10        ASSIGN_OBJ                                               !1, 'substituteEntities'
         11        OP_DATA                                                  <false>
   10    12        ASSIGN_OBJ                                               !1, 'formatOutput'
         13        OP_DATA                                                  <false>
   12    14        INIT_FCALL                                               'mb_detect_order'
         15        SEND_VAL                                                 'ASCII%2CUTF-8%2CISO-8859-1%2Cwindows-1252%2Ciso-8859-15'
         16        DO_ICALL                                                 
   37    17        INIT_METHOD_CALL                                         !1, 'loadHTML'
         18        INIT_FCALL                                               'loadnprepare'
         19        SEND_VAR                                                 !0
         20        DO_FCALL                                      0  $13     
         21        SEND_VAR_NO_REF_EX                                       $13
         22        DO_FCALL                                      0          
   39    23        FETCH_OBJ_R                                      ~15     !1, 'childNodes'
         24      > FE_RESET_R                                       $16     ~15, ->34
         25    > > FE_FETCH_R                                               $16, !2, ->34
   40    26    >   FETCH_OBJ_R                                      ~17     !2, 'nodeType'
         27        IS_IDENTICAL                                             ~17, 7
         28      > JMPZ                                                     ~18, ->33
   41    29    >   INIT_METHOD_CALL                                         !1, 'removeChild'
         30        SEND_VAR_EX                                              !2
         31        DO_FCALL                                      0          
   42    32      > JMP                                                      ->34
   39    33    > > JMP                                                      ->25
         34    >   FE_FREE                                                  $16
   47    35        INIT_FCALL                                               'preg_replace'
   48    36        SEND_VAL                                                 <array>
   50    37        SEND_VAL                                                 ''
         38        INIT_METHOD_CALL                                         !1, 'saveHTML'
         39        DO_FCALL                                      0  $20     
         40        SEND_VAR                                                 $20
         41        DO_ICALL                                         $21     
   47    42        ASSIGN                                                   !3, $21
   52    43        INIT_FCALL                                               'var_dump'
         44        INIT_FCALL                                               'trim'
         45        SEND_VAR                                                 !3
         46        DO_ICALL                                         $23     
         47        SEND_VAR                                                 $23
         48        DO_ICALL                                                 
         49      > RETURN                                                   1

Function loadnprepare:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 46
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 23
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 40
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
Branch analysis from position: 23
Branch analysis from position: 11
Branch analysis from position: 46
filename:       /in/HnhdC
function name:  loadNprepare
number of ops:  48
compiled vars:  !0 = $content, !1 = $encod, !2 = $headpos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      ''
   14     2        ISSET_ISEMPTY_CV                                 ~3      !0
          3        BOOL_NOT                                         ~4      ~3
          4      > JMPZ                                                     ~4, ->46
   15     5    >   ISSET_ISEMPTY_CV                                         !1
          6      > JMPZ                                                     ~5, ->11
   16     7    >   INIT_FCALL                                               'mb_detect_encoding'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $6      
         10        ASSIGN                                                   !1, $6
   17    11    >   INIT_FCALL                                               'mb_strpos'
         12        SEND_VAR                                                 !0
         13        SEND_VAL                                                 '%3Chead%3E'
         14        DO_ICALL                                         $8      
         15        ASSIGN                                                   !2, $8
   18    16        TYPE_CHECK                                    4          !2
         17      > JMPZ                                                     ~10, ->23
   19    18    >   INIT_FCALL                                               'mb_strpos'
         19        SEND_VAR                                                 !0
         20        SEND_VAL                                                 '%3CHEAD%3E'
         21        DO_ICALL                                         $11     
         22        ASSIGN                                                   !2, $11
   20    23    >   TYPE_CHECK                                  1018          !2
         24      > JMPZ                                                     ~13, ->40
   21    25    >   ASSIGN_OP                                     1          !2, 6
   22    26        INIT_FCALL                                               'mb_substr'
         27        SEND_VAR                                                 !0
         28        SEND_VAL                                                 0
         29        SEND_VAR                                                 !2
         30        DO_ICALL                                         $15     
         31        CONCAT                                           ~16     $15, '%3Cmeta+http-equiv%3D%22Content-Type%22+content%3D%22text%2Fhtml%3B+charset%3D'
         32        CONCAT                                           ~17     ~16, !1
         33        CONCAT                                           ~18     ~17, '%22%3E'
         34        INIT_FCALL                                               'mb_substr'
         35        SEND_VAR                                                 !0
         36        SEND_VAR                                                 !2
         37        DO_ICALL                                         $19     
         38        CONCAT                                           ~20     ~18, $19
         39        ASSIGN                                                   !0, ~20
   24    40    >   INIT_FCALL                                               'mb_convert_encoding'
         41        SEND_VAR                                                 !0
         42        SEND_VAL                                                 'HTML-ENTITIES'
         43        SEND_VAR                                                 !1
         44        DO_ICALL                                         $22     
         45        ASSIGN                                                   !0, $22
   26    46    > > RETURN                                                   !0
   27    47*     > RETURN                                                   null

End of function loadnprepare

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.15 ms | 1411 KiB | 30 Q