3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getbody($url) { $dom = new DOMDocument; $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_URL, $url); $file = curl_exec($curl); curl_close($curl); $dom->loadHTML($file); //$dom->loadHTMLFile($url); $bodies = $dom->getElementsByTagName('body'); assert($bodies->length === 1); $body = $bodies->item(0); for ($i = 0; $i < $body->children->length; $i++) { $body->remove($body->children->item($i)); } $stringbody = $dom->saveHTML($body); return $stringbody; } $url = "http://stackoverflow.com"; //$url = "http://www.barcelona.com"; $body = getbody($url); //var_dump($body); ?> <html> <head></head> <body> <?php echo "BODY ripped from: ".$url."<br/>"; echo "<textarea rows='40' cols='200' >".$body."</textarea>"; ?> </body> </html>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/L4gNe
function name:  (null)
number of ops:  14
compiled vars:  !0 = $url, !1 = $body
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN                                                   !0, 'http%3A%2F%2Fstackoverflow.com'
   23     1        INIT_FCALL                                               'getbody'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   27     5        ECHO                                                     '%3Chtml%3E%0A%3Chead%3E%3C%2Fhead%3E%0A%3Cbody%3E%0A'
   31     6        CONCAT                                           ~5      'BODY+ripped+from%3A+', !0
          7        CONCAT                                           ~6      ~5, '%3Cbr%2F%3E'
          8        ECHO                                                     ~6
   32     9        CONCAT                                           ~7      '%3Ctextarea+rows%3D%2740%27+cols%3D%27200%27+%3E', !1
         10        CONCAT                                           ~8      ~7, '%3C%2Ftextarea%3E'
         11        ECHO                                                     ~8
   34    12        ECHO                                                     '%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
   35    13      > RETURN                                                   1

Function getbody:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 46
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 46
Branch analysis from position: 58
Branch analysis from position: 46
filename:       /in/L4gNe
function name:  getbody
number of ops:  64
compiled vars:  !0 = $url, !1 = $dom, !2 = $curl, !3 = $file, !4 = $bodies, !5 = $body, !6 = $i, !7 = $stringbody
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        NEW                                              $8      'DOMDocument'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $8
    4     4        INIT_FCALL_BY_NAME                                       'curl_init'
          5        DO_FCALL                                      0  $11     
          6        ASSIGN                                                   !2, $11
    5     7        INIT_FCALL_BY_NAME                                       'curl_setopt'
          8        SEND_VAR_EX                                              !2
          9        FETCH_CONSTANT                                   ~13     'CURLOPT_RETURNTRANSFER'
         10        SEND_VAL_EX                                              ~13
         11        SEND_VAL_EX                                              <true>
         12        DO_FCALL                                      0          
    6    13        INIT_FCALL_BY_NAME                                       'curl_setopt'
         14        SEND_VAR_EX                                              !2
         15        FETCH_CONSTANT                                   ~15     'CURLOPT_URL'
         16        SEND_VAL_EX                                              ~15
         17        SEND_VAR_EX                                              !0
         18        DO_FCALL                                      0          
    7    19        INIT_FCALL_BY_NAME                                       'curl_exec'
         20        SEND_VAR_EX                                              !2
         21        DO_FCALL                                      0  $17     
         22        ASSIGN                                                   !3, $17
    8    23        INIT_FCALL_BY_NAME                                       'curl_close'
         24        SEND_VAR_EX                                              !2
         25        DO_FCALL                                      0          
   10    26        INIT_METHOD_CALL                                         !1, 'loadHTML'
         27        SEND_VAR_EX                                              !3
         28        DO_FCALL                                      0          
   12    29        INIT_METHOD_CALL                                         !1, 'getElementsByTagName'
         30        SEND_VAL_EX                                              'body'
         31        DO_FCALL                                      0  $21     
         32        ASSIGN                                                   !4, $21
   13    33        ASSERT_CHECK                                             
         34        INIT_FCALL                                               'assert'
         35        FETCH_OBJ_R                                      ~23     !4, 'length'
         36        IS_IDENTICAL                                     ~24     ~23, 1
         37        SEND_VAL                                                 ~24
         38        SEND_VAL                                                 'assert%28%24bodies-%3Elength+%3D%3D%3D+1%29'
         39        DO_ICALL                                                 
   14    40        INIT_METHOD_CALL                                         !4, 'item'
         41        SEND_VAL_EX                                              0
         42        DO_FCALL                                      0  $26     
         43        ASSIGN                                                   !5, $26
   15    44        ASSIGN                                                   !6, 0
         45      > JMP                                                      ->54
   16    46    >   INIT_METHOD_CALL                                         !5, 'remove'
         47        FETCH_OBJ_R                                      ~29     !5, 'children'
         48        INIT_METHOD_CALL                                         ~29, 'item'
         49        SEND_VAR_EX                                              !6
         50        DO_FCALL                                      0  $30     
         51        SEND_VAR_NO_REF_EX                                       $30
         52        DO_FCALL                                      0          
   15    53        PRE_INC                                                  !6
         54    >   FETCH_OBJ_R                                      ~33     !5, 'children'
         55        FETCH_OBJ_R                                      ~34     ~33, 'length'
         56        IS_SMALLER                                               !6, ~34
         57      > JMPNZ                                                    ~35, ->46
   18    58    >   INIT_METHOD_CALL                                         !1, 'saveHTML'
         59        SEND_VAR_EX                                              !5
         60        DO_FCALL                                      0  $36     
         61        ASSIGN                                                   !7, $36
   19    62      > RETURN                                                   !7
   20    63*     > RETURN                                                   null

End of function getbody

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.74 ms | 1407 KiB | 16 Q