3v4l.org

run code in 300+ PHP versions simultaneously
<?php $HTML_string = ' <h1>Test of h1</h1> <p>This is a p test.</p> <h2>Test of h2</h2> <p>This is a p test with a <strong>strong emphasis</strong> followed by this.</p> <h3>Test of h3</h3> <p>This here is a link: <a href="http://www.example.com/1">Example.com</a>.<br> And this is a linebreak.</p> <p>Another paragraph, followed by a horizontal line:</p> <hr> <p>A final paragraph with <a href="http://www.example.com/2"><em>some emphasis</em> inside a link</a>.</p> '; function convertHTag(DOMNode $node) { $textNode = $node->ownerDocument->createTextNode(strtoupper($node->nodeName). ': ' . trim($node->textContent)); $node->ownerDocument->importNode($textNode); $node->parentNode->replaceChild($node, $textNode); } function convertATag(DOMNode $node) { $textNode = $node->ownerDocument->createTextNode(trim($node->textContent) . ' ( ' . $node->getAttribute('href') . ' ) '); $node->ownerDocument->importNode($textNode); $node->parentNode->replaceChild($node, $textNode); } function convertStrongTag(DOMNode $node) { $textNode = $node->ownerDocument->createTextNode(' **' . trim($node->textContent) . '** '); $node->ownerDocument->importNode($textNode); $node->parentNode->replaceChild($node, $textNode); } function convertEmTag(DOMNode $node) { $textNode = $node->ownerDocument->createTextNode(' *' . trim($node->textContent) . '* '); $node->ownerDocument->importNode($textNode); $node->parentNode->replaceChild($node, $textNode); } function convertPTag(DOMNode $node) { return trim($node->textContent); $node->ownerDocument->importNode($textNode); $node->parentNode->replaceChild($node, $textNode); } $doc = new DOMDocument(); $doc->loadHTML($HTML_string); $xpath = new DOMXpath($doc); foreach($xpath->query('/html/body/*[self::h1 or self::h2 or self::h3]') as $node) { convertHTag($node); } foreach($xpath->query('//a') as $node) { convertATag($node); } foreach($xpath->query('//strong') as $node) { convertStrongTag($node); } foreach($xpath->query('//em') as $node) { convertEmTag($node); } foreach($xpath->query('//p') as $node) { convertPTag($node); } echo $doc->textContent; /* H1: Test of h1 This is a p test. H2: Test of h2 This is a p test with a **strong emphasis** followed by this. H3: Test of h3 This here is a link: Example.com ( http://www.example.com/1 ). And this is a linebreak. Another paragraph, followed by a horizontal line: --------------- A final paragraph with *some emphasis* inside a link ( http://www.example.com/2 ). */
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 20
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 30
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 30
2 jumps found. (Code = 77) Position 1 = 35, Position 2 = 40
Branch analysis from position: 35
2 jumps found. (Code = 78) Position 1 = 36, Position 2 = 40
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 40
2 jumps found. (Code = 77) Position 1 = 45, Position 2 = 50
Branch analysis from position: 45
2 jumps found. (Code = 78) Position 1 = 46, Position 2 = 50
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 50
2 jumps found. (Code = 77) Position 1 = 55, Position 2 = 60
Branch analysis from position: 55
2 jumps found. (Code = 78) Position 1 = 56, Position 2 = 60
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
Branch analysis from position: 60
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
Branch analysis from position: 50
Branch analysis from position: 40
Branch analysis from position: 30
Branch analysis from position: 20
filename:       /in/4gmpn
function name:  (null)
number of ops:  64
compiled vars:  !0 = $HTML_string, !1 = $doc, !2 = $xpath, !3 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%0A%0A%09%3Ch1%3ETest+of+h1%3C%2Fh1%3E%0A%09%3Cp%3EThis+is+a+p+test.%3C%2Fp%3E%0A%0A%09%3Ch2%3ETest+of+h2%3C%2Fh2%3E%0A%09%3Cp%3EThis+is+a+p+test+with+a+%3Cstrong%3Estrong+emphasis%3C%2Fstrong%3E+followed+by+this.%3C%2Fp%3E%0A%0A%09%3Ch3%3ETest+of+h3%3C%2Fh3%3E%0A%09%3Cp%3EThis+here+is+a+link%3A+%3Ca+href%3D%22http%3A%2F%2Fwww.example.com%2F1%22%3EExample.com%3C%2Fa%3E.%3Cbr%3E%0A%09And+this+is+a+linebreak.%3C%2Fp%3E%0A%0A%09%3Cp%3EAnother+paragraph%2C+followed+by+a+horizontal+line%3A%3C%2Fp%3E%0A%0A%09%3Chr%3E%0A%0A%09%3Cp%3EA+final+paragraph+with+%3Ca+href%3D%22http%3A%2F%2Fwww.example.com%2F2%22%3E%3Cem%3Esome+emphasis%3C%2Fem%3E+inside+a+link%3C%2Fa%3E.%3C%2Fp%3E%0A%09'
   54     1        NEW                                              $5      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $5
   55     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
   56     7        NEW                                              $9      'DOMXpath'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !2, $9
   58    11        INIT_METHOD_CALL                                         !2, 'query'
         12        SEND_VAL_EX                                              '%2Fhtml%2Fbody%2F%2A%5Bself%3A%3Ah1+or+self%3A%3Ah2+or+self%3A%3Ah3%5D'
         13        DO_FCALL                                      0  $12     
         14      > FE_RESET_R                                       $13     $12, ->20
         15    > > FE_FETCH_R                                               $13, !3, ->20
   59    16    >   INIT_FCALL                                               'converthtag'
         17        SEND_VAR                                                 !3
         18        DO_FCALL                                      0          
   58    19      > JMP                                                      ->15
         20    >   FE_FREE                                                  $13
   62    21        INIT_METHOD_CALL                                         !2, 'query'
         22        SEND_VAL_EX                                              '%2F%2Fa'
         23        DO_FCALL                                      0  $15     
         24      > FE_RESET_R                                       $16     $15, ->30
         25    > > FE_FETCH_R                                               $16, !3, ->30
   63    26    >   INIT_FCALL                                               'convertatag'
         27        SEND_VAR                                                 !3
         28        DO_FCALL                                      0          
   62    29      > JMP                                                      ->25
         30    >   FE_FREE                                                  $16
   66    31        INIT_METHOD_CALL                                         !2, 'query'
         32        SEND_VAL_EX                                              '%2F%2Fstrong'
         33        DO_FCALL                                      0  $18     
         34      > FE_RESET_R                                       $19     $18, ->40
         35    > > FE_FETCH_R                                               $19, !3, ->40
   67    36    >   INIT_FCALL                                               'convertstrongtag'
         37        SEND_VAR                                                 !3
         38        DO_FCALL                                      0          
   66    39      > JMP                                                      ->35
         40    >   FE_FREE                                                  $19
   71    41        INIT_METHOD_CALL                                         !2, 'query'
         42        SEND_VAL_EX                                              '%2F%2Fem'
         43        DO_FCALL                                      0  $21     
         44      > FE_RESET_R                                       $22     $21, ->50
         45    > > FE_FETCH_R                                               $22, !3, ->50
   72    46    >   INIT_FCALL                                               'convertemtag'
         47        SEND_VAR                                                 !3
         48        DO_FCALL                                      0          
   71    49      > JMP                                                      ->45
         50    >   FE_FREE                                                  $22
   76    51        INIT_METHOD_CALL                                         !2, 'query'
         52        SEND_VAL_EX                                              '%2F%2Fp'
         53        DO_FCALL                                      0  $24     
         54      > FE_RESET_R                                       $25     $24, ->60
         55    > > FE_FETCH_R                                               $25, !3, ->60
   77    56    >   INIT_FCALL                                               'convertptag'
         57        SEND_VAR                                                 !3
         58        DO_FCALL                                      0          
   76    59      > JMP                                                      ->55
         60    >   FE_FREE                                                  $25
   80    61        FETCH_OBJ_R                                      ~27     !1, 'textContent'
         62        ECHO                                                     ~27
  103    63      > RETURN                                                   1

Function converthtag:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4gmpn
function name:  convertHTag
number of ops:  26
compiled vars:  !0 = $node, !1 = $textNode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   24     1        FETCH_OBJ_R                                      ~2      !0, 'ownerDocument'
          2        INIT_METHOD_CALL                                         ~2, 'createTextNode'
          3        INIT_FCALL                                               'strtoupper'
          4        FETCH_OBJ_R                                      ~3      !0, 'nodeName'
          5        SEND_VAL                                                 ~3
          6        DO_ICALL                                         $4      
          7        CONCAT                                           ~5      $4, '%3A+'
          8        INIT_FCALL                                               'trim'
          9        FETCH_OBJ_R                                      ~6      !0, 'textContent'
         10        SEND_VAL                                                 ~6
         11        DO_ICALL                                         $7      
         12        CONCAT                                           ~8      ~5, $7
         13        SEND_VAL_EX                                              ~8
         14        DO_FCALL                                      0  $9      
         15        ASSIGN                                                   !1, $9
   25    16        FETCH_OBJ_R                                      ~11     !0, 'ownerDocument'
         17        INIT_METHOD_CALL                                         ~11, 'importNode'
         18        SEND_VAR_EX                                              !1
         19        DO_FCALL                                      0          
   26    20        FETCH_OBJ_R                                      ~13     !0, 'parentNode'
         21        INIT_METHOD_CALL                                         ~13, 'replaceChild'
         22        SEND_VAR_EX                                              !0
         23        SEND_VAR_EX                                              !1
         24        DO_FCALL                                      0          
   27    25      > RETURN                                                   null

End of function converthtag

Function convertatag:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4gmpn
function name:  convertATag
number of ops:  26
compiled vars:  !0 = $node, !1 = $textNode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   30     1        FETCH_OBJ_R                                      ~2      !0, 'ownerDocument'
          2        INIT_METHOD_CALL                                         ~2, 'createTextNode'
          3        INIT_FCALL                                               'trim'
          4        FETCH_OBJ_R                                      ~3      !0, 'textContent'
          5        SEND_VAL                                                 ~3
          6        DO_ICALL                                         $4      
          7        CONCAT                                           ~5      $4, '+%28+'
          8        INIT_METHOD_CALL                                         !0, 'getAttribute'
          9        SEND_VAL_EX                                              'href'
         10        DO_FCALL                                      0  $6      
         11        CONCAT                                           ~7      ~5, $6
         12        CONCAT                                           ~8      ~7, '+%29+'
         13        SEND_VAL_EX                                              ~8
         14        DO_FCALL                                      0  $9      
         15        ASSIGN                                                   !1, $9
   31    16        FETCH_OBJ_R                                      ~11     !0, 'ownerDocument'
         17        INIT_METHOD_CALL                                         ~11, 'importNode'
         18        SEND_VAR_EX                                              !1
         19        DO_FCALL                                      0          
   32    20        FETCH_OBJ_R                                      ~13     !0, 'parentNode'
         21        INIT_METHOD_CALL                                         ~13, 'replaceChild'
         22        SEND_VAR_EX                                              !0
         23        SEND_VAR_EX                                              !1
         24        DO_FCALL                                      0          
   33    25      > RETURN                                                   null

End of function convertatag

Function convertstrongtag:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4gmpn
function name:  convertStrongTag
number of ops:  22
compiled vars:  !0 = $node, !1 = $textNode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   RECV                                             !0      
   36     1        FETCH_OBJ_R                                      ~2      !0, 'ownerDocument'
          2        INIT_METHOD_CALL                                         ~2, 'createTextNode'
          3        INIT_FCALL                                               'trim'
          4        FETCH_OBJ_R                                      ~3      !0, 'textContent'
          5        SEND_VAL                                                 ~3
          6        DO_ICALL                                         $4      
          7        CONCAT                                           ~5      '+%2A%2A', $4
          8        CONCAT                                           ~6      ~5, '%2A%2A+'
          9        SEND_VAL_EX                                              ~6
         10        DO_FCALL                                      0  $7      
         11        ASSIGN                                                   !1, $7
   37    12        FETCH_OBJ_R                                      ~9      !0, 'ownerDocument'
         13        INIT_METHOD_CALL                                         ~9, 'importNode'
         14        SEND_VAR_EX                                              !1
         15        DO_FCALL                                      0          
   38    16        FETCH_OBJ_R                                      ~11     !0, 'parentNode'
         17        INIT_METHOD_CALL                                         ~11, 'replaceChild'
         18        SEND_VAR_EX                                              !0
         19        SEND_VAR_EX                                              !1
         20        DO_FCALL                                      0          
   39    21      > RETURN                                                   null

End of function convertstrongtag

Function convertemtag:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4gmpn
function name:  convertEmTag
number of ops:  22
compiled vars:  !0 = $node, !1 = $textNode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
   42     1        FETCH_OBJ_R                                      ~2      !0, 'ownerDocument'
          2        INIT_METHOD_CALL                                         ~2, 'createTextNode'
          3        INIT_FCALL                                               'trim'
          4        FETCH_OBJ_R                                      ~3      !0, 'textContent'
          5        SEND_VAL                                                 ~3
          6        DO_ICALL                                         $4      
          7        CONCAT                                           ~5      '+%2A', $4
          8        CONCAT                                           ~6      ~5, '%2A+'
          9        SEND_VAL_EX                                              ~6
         10        DO_FCALL                                      0  $7      
         11        ASSIGN                                                   !1, $7
   43    12        FETCH_OBJ_R                                      ~9      !0, 'ownerDocument'
         13        INIT_METHOD_CALL                                         ~9, 'importNode'
         14        SEND_VAR_EX                                              !1
         15        DO_FCALL                                      0          
   44    16        FETCH_OBJ_R                                      ~11     !0, 'parentNode'
         17        INIT_METHOD_CALL                                         ~11, 'replaceChild'
         18        SEND_VAR_EX                                              !0
         19        SEND_VAR_EX                                              !1
         20        DO_FCALL                                      0          
   45    21      > RETURN                                                   null

End of function convertemtag

Function convertptag:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/4gmpn
function name:  convertPTag
number of ops:  16
compiled vars:  !0 = $node, !1 = $textNode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   48     1        INIT_FCALL                                               'trim'
          2        FETCH_OBJ_R                                      ~2      !0, 'textContent'
          3        SEND_VAL                                                 ~2
          4        DO_ICALL                                         $3      
          5      > RETURN                                                   $3
   49     6*       FETCH_OBJ_R                                      ~4      !0, 'ownerDocument'
          7*       INIT_METHOD_CALL                                         ~4, 'importNode'
          8*       SEND_VAR_EX                                              !1
          9*       DO_FCALL                                      0          
   50    10*       FETCH_OBJ_R                                      ~6      !0, 'parentNode'
         11*       INIT_METHOD_CALL                                         ~6, 'replaceChild'
         12*       SEND_VAR_EX                                              !0
         13*       SEND_VAR_EX                                              !1
         14*       DO_FCALL                                      0          
   51    15*     > RETURN                                                   null

End of function convertptag

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.71 ms | 1415 KiB | 22 Q