3v4l.org

run code in 300+ PHP versions simultaneously
<?php $article = '<html><body><div>some text</div><iframe name="notyoutube" src="http://example.com"></iframe><p>some more text</p> <iframe width="560" height="315" src="https://www.youtube.com/embed/bpcNPHqs4ng" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe><div>one last div</div></body></html>'; $doc = new DOMDocument(); $doc->loadHTML($article, LIBXML_HTML_NODEFDTD); $xpath = new DOMXPath($doc); foreach ($xpath->query("//iframe[contains(@src, 'youtube')]") as $youtube) { // create a new node $node = $doc->createElement('amp-youtube'); // set attributes $node->setAttribute('data-videoid', basename(parse_url($youtube->getAttribute('src'), PHP_URL_PATH))); $node->setAttribute('width', $youtube->getAttribute('width')); $node->setAttribute('height', $youtube->getAttribute('height')); $node->setAttribute('layout', 'responsive'); // and now replace the old node $youtube->parentNode->replaceChild($node, $youtube); } echo $doc->saveHTML();
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 59
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 59
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 59
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
filename:       /in/lNUY5
function name:  (null)
number of ops:  64
compiled vars:  !0 = $article, !1 = $doc, !2 = $xpath, !3 = $youtube, !4 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%3Chtml%3E%3Cbody%3E%3Cdiv%3Esome+text%3C%2Fdiv%3E%3Ciframe+name%3D%22notyoutube%22+src%3D%22http%3A%2F%2Fexample.com%22%3E%3C%2Fiframe%3E%3Cp%3Esome+more+text%3C%2Fp%3E%0A%3Ciframe+width%3D%22560%22+height%3D%22315%22+src%3D%22https%3A%2F%2Fwww.youtube.com%2Fembed%2FbpcNPHqs4ng%22+frameborder%3D%220%22+allow%3D%22accelerometer%3B+autoplay%3B+encrypted-media%3B+gyroscope%3B+picture-in-picture%22+allowfullscreen%3E%3C%2Fiframe%3E%3Cdiv%3Eone+last+div%3C%2Fdiv%3E%3C%2Fbody%3E%3C%2Fhtml%3E'
    4     1        NEW                                              $6      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $6
    5     4        INIT_METHOD_CALL                                         !1, 'loadHTML'
          5        SEND_VAR_EX                                              !0
          6        SEND_VAL_EX                                              4
          7        DO_FCALL                                      0          
    6     8        NEW                                              $10     'DOMXPath'
          9        SEND_VAR_EX                                              !1
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !2, $10
    7    12        INIT_METHOD_CALL                                         !2, 'query'
         13        SEND_VAL_EX                                              '%2F%2Fiframe%5Bcontains%28%40src%2C+%27youtube%27%29%5D'
         14        DO_FCALL                                      0  $13     
         15      > FE_RESET_R                                       $14     $13, ->59
         16    > > FE_FETCH_R                                               $14, !3, ->59
    9    17    >   INIT_METHOD_CALL                                         !1, 'createElement'
         18        SEND_VAL_EX                                              'amp-youtube'
         19        DO_FCALL                                      0  $15     
         20        ASSIGN                                                   !4, $15
   11    21        INIT_METHOD_CALL                                         !4, 'setAttribute'
         22        SEND_VAL_EX                                              'data-videoid'
         23        INIT_FCALL                                               'basename'
         24        INIT_FCALL                                               'parse_url'
         25        INIT_METHOD_CALL                                         !3, 'getAttribute'
         26        SEND_VAL_EX                                              'src'
         27        DO_FCALL                                      0  $17     
         28        SEND_VAR                                                 $17
         29        SEND_VAL                                                 5
         30        DO_ICALL                                         $18     
         31        SEND_VAR                                                 $18
         32        DO_ICALL                                         $19     
         33        SEND_VAR_NO_REF_EX                                       $19
         34        DO_FCALL                                      0          
   12    35        INIT_METHOD_CALL                                         !4, 'setAttribute'
         36        SEND_VAL_EX                                              'width'
         37        INIT_METHOD_CALL                                         !3, 'getAttribute'
         38        SEND_VAL_EX                                              'width'
         39        DO_FCALL                                      0  $21     
         40        SEND_VAR_NO_REF_EX                                       $21
         41        DO_FCALL                                      0          
   13    42        INIT_METHOD_CALL                                         !4, 'setAttribute'
         43        SEND_VAL_EX                                              'height'
         44        INIT_METHOD_CALL                                         !3, 'getAttribute'
         45        SEND_VAL_EX                                              'height'
         46        DO_FCALL                                      0  $23     
         47        SEND_VAR_NO_REF_EX                                       $23
         48        DO_FCALL                                      0          
   14    49        INIT_METHOD_CALL                                         !4, 'setAttribute'
         50        SEND_VAL_EX                                              'layout'
         51        SEND_VAL_EX                                              'responsive'
         52        DO_FCALL                                      0          
   16    53        FETCH_OBJ_R                                      ~26     !3, 'parentNode'
         54        INIT_METHOD_CALL                                         ~26, 'replaceChild'
         55        SEND_VAR_EX                                              !4
         56        SEND_VAR_EX                                              !3
         57        DO_FCALL                                      0          
    7    58      > JMP                                                      ->16
         59    >   FE_FREE                                                  $14
   18    60        INIT_METHOD_CALL                                         !1, 'saveHTML'
         61        DO_FCALL                                      0  $28     
         62        ECHO                                                     $28
         63      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.53 ms | 1016 KiB | 15 Q