3v4l.org

run code in 300+ PHP versions simultaneously
<?php $s = '<p>I am <30 years old and weight <12st</p>'; $libxmlErrorState = libxml_use_internal_errors(true); function getLastErrorPos($code) { $errors = array_filter(libxml_get_errors(), function ($e) use ($code) { return $e->code === $code; }); if ( !$errors ) return false; $lastError = array_pop($errors); return ['line' => $lastError->line - 1, 'column' => $lastError->column - 2 ]; } define('XML_ERR_NAME_REQUIRED', 68); // xmlParseEntityRef: no name $patternTemplate = '~(?:.*\R){%d}.{%d}\K<~A'; $dom = new DOMDocument; $dom->loadHTML($s, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); while ( false !== $position = getLastErrorPos(XML_ERR_NAME_REQUIRED) ) { libxml_clear_errors(); $pattern = vsprintf($patternTemplate, $position); $s = preg_replace($pattern, '&lt;', $s, 1); $dom = new DOMDocument; $dom->loadHTML($s, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); } echo $dom->saveHTML(); libxml_clear_errors(); libxml_use_internal_errors($libxmlErrorState);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 18
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 46, Position 2 = 18
Branch analysis from position: 46
Branch analysis from position: 18
filename:       /in/b6WOB
function name:  (null)
number of ops:  55
compiled vars:  !0 = $s, !1 = $libxmlErrorState, !2 = $patternTemplate, !3 = $dom, !4 = $pattern, !5 = $position
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%3Cp%3EI+am+%3C30+years+old+and+weight+%3C12st%3C%2Fp%3E'
    5     1        INIT_FCALL                                               'libxml_use_internal_errors'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $7      
          4        ASSIGN                                                   !1, $7
   16     5        INIT_FCALL                                               'define'
          6        SEND_VAL                                                 'XML_ERR_NAME_REQUIRED'
          7        SEND_VAL                                                 68
          8        DO_ICALL                                                 
   18     9        ASSIGN                                                   !2, '%7E%28%3F%3A.%2A%5CR%29%7B%25d%7D.%7B%25d%7D%5CK%3C%7EA'
   20    10        NEW                                              $11     'DOMDocument'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !3, $11
   21    13        INIT_METHOD_CALL                                         !3, 'loadHTML'
         14        SEND_VAR_EX                                              !0
         15        SEND_VAL_EX                                              8196
         16        DO_FCALL                                      0          
   23    17      > JMP                                                      ->39
   25    18    >   INIT_FCALL                                               'libxml_clear_errors'
         19        DO_ICALL                                                 
   26    20        INIT_FCALL                                               'vsprintf'
         21        SEND_VAR                                                 !2
         22        SEND_VAR                                                 !5
         23        DO_ICALL                                         $16     
         24        ASSIGN                                                   !4, $16
   28    25        INIT_FCALL                                               'preg_replace'
         26        SEND_VAR                                                 !4
         27        SEND_VAL                                                 '%26lt%3B'
         28        SEND_VAR                                                 !0
         29        SEND_VAL                                                 1
         30        DO_ICALL                                         $18     
         31        ASSIGN                                                   !0, $18
   29    32        NEW                                              $20     'DOMDocument'
         33        DO_FCALL                                      0          
         34        ASSIGN                                                   !3, $20
   30    35        INIT_METHOD_CALL                                         !3, 'loadHTML'
         36        SEND_VAR_EX                                              !0
         37        SEND_VAL_EX                                              8196
         38        DO_FCALL                                      0          
   23    39    >   INIT_FCALL                                               'getlasterrorpos'
         40        FETCH_CONSTANT                                   ~24     'XML_ERR_NAME_REQUIRED'
         41        SEND_VAL                                                 ~24
         42        DO_FCALL                                      0  $25     
         43        ASSIGN                                           ~26     !5, $25
         44        TYPE_CHECK                                  1018          ~26
         45      > JMPNZ                                                    ~27, ->18
   33    46    >   INIT_METHOD_CALL                                         !3, 'saveHTML'
         47        DO_FCALL                                      0  $28     
         48        ECHO                                                     $28
   35    49        INIT_FCALL                                               'libxml_clear_errors'
         50        DO_ICALL                                                 
   36    51        INIT_FCALL                                               'libxml_use_internal_errors'
         52        SEND_VAR                                                 !1
         53        DO_ICALL                                                 
         54      > RETURN                                                   1

Function getlasterrorpos:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/b6WOB
function name:  getLastErrorPos
number of ops:  25
compiled vars:  !0 = $code, !1 = $errors, !2 = $lastError
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        INIT_FCALL                                               'array_filter'
          2        INIT_FCALL                                               'libxml_get_errors'
          3        DO_ICALL                                         $3      
          4        SEND_VAR                                                 $3
          5        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fb6WOB%3A8%240'
          6        BIND_LEXICAL                                             ~4, !0
          7        SEND_VAL                                                 ~4
          8        DO_ICALL                                         $5      
          9        ASSIGN                                                   !1, $5
    9    10        BOOL_NOT                                         ~7      !1
         11      > JMPZ                                                     ~7, ->13
   10    12    > > RETURN                                                   <false>
   12    13    >   INIT_FCALL                                               'array_pop'
         14        SEND_REF                                                 !1
         15        DO_ICALL                                         $8      
         16        ASSIGN                                                   !2, $8
   13    17        FETCH_OBJ_R                                      ~10     !2, 'line'
         18        SUB                                              ~11     ~10, 1
         19        INIT_ARRAY                                       ~12     ~11, 'line'
         20        FETCH_OBJ_R                                      ~13     !2, 'column'
         21        SUB                                              ~14     ~13, 2
         22        ADD_ARRAY_ELEMENT                                ~12     ~14, 'column'
         23      > RETURN                                                   ~12
   14    24*     > RETURN                                                   null

End of function getlasterrorpos

Function %00%7Bclosure%7D%2Fin%2Fb6WOB%3A8%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/b6WOB
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $e, !1 = $code
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        FETCH_OBJ_R                                      ~2      !0, 'code'
          3        IS_IDENTICAL                                     ~3      !1, ~2
          4      > RETURN                                                   ~3
          5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Fb6WOB%3A8%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.15 ms | 1419 KiB | 30 Q