3v4l.org

run code in 300+ PHP versions simultaneously
<?php function curl($url) { $options = Array( CURLOPT_RETURNTRANSFER => TRUE, // Setting cURL's option to return the webpage data CURLOPT_FOLLOWLOCATION => TRUE, // Setting cURL to follow 'location' HTTP headers CURLOPT_AUTOREFERER => TRUE, // Automatically set the referer where following 'location' HTTP headers CURLOPT_CONNECTTIMEOUT => 120, // Setting the amount of time (in seconds) before the request times out CURLOPT_TIMEOUT => 120, // Setting the maximum amount of time for cURL to execute queries CURLOPT_MAXREDIRS => 10, // Setting the maximum number of redirections to follow CURLOPT_USERAGENT => "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1a2pre) Gecko/2008073000 Shredder/3.0a2pre ThunderBrowse/3.2.1.8", // Setting the useragent CURLOPT_URL => $url, // Setting cURL's URL option with the $url variable passed into the function ); $ch = curl_init(); // Initialising cURL curl_setopt_array($ch, $options); // Setting cURL's options using the previously assigned array data in $options $data = curl_exec($ch); // Executing the cURL request and assigning the returned data to the $data variable curl_close($ch); // Closing cURL return $data; // Returning the data from the function } function regex_scrape($regex,$results_page){ preg_match_all($regex,$results_page,$match); return $match; } $continue = TRUE; $prices = array(); $url = "https://www.airbnb.de/s/Prague~Prague-1--Czech-Republic"; while ($continue == TRUE) { $results_page = curl($url); // Downloading the results page using our curl() funtion $prices2 = regex_scrape('/<span class=\"h3 price-amount\">(.*)span>/',$results_page); //PRINTING ARRAY SUM NOT WORKIN var_dump($prices2[0]); echo 'TOTAL: ' . array_sum(array_values($prices2[0])); $prices = array_merge($prices,$prices2[0]); if (strpos($results_page, "<li class=\"next next_page\">")) { $continue = FALSE; preg_match('/<li class="next next_page"><a target=".*" rel="next" href="(.*)"><i class="icon icon-caret-right">/',$results_page,$url); $url = 'https://www.airbnb.de' . $url[1]; } else { $continue = FALSE; // Setting $continue to FALSE if there's no 'Next' link } sleep(rand(0,1)); // Sleep for 3 to 5 seconds. Useful if not using proxies. We don't want to get into trouble. } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 4
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 47
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 4
Branch analysis from position: 57
Branch analysis from position: 4
Branch analysis from position: 47
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 4
Branch analysis from position: 57
Branch analysis from position: 4
filename:       /in/eleo0
function name:  (null)
number of ops:  58
compiled vars:  !0 = $continue, !1 = $prices, !2 = $url, !3 = $results_page, !4 = $prices2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   ASSIGN                                                   !0, <true>
   29     1        ASSIGN                                                   !1, <array>
   30     2        ASSIGN                                                   !2, 'https%3A%2F%2Fwww.airbnb.de%2Fs%2FPrague%7EPrague-1--Czech-Republic'
   32     3      > JMP                                                      ->55
   33     4    >   INIT_FCALL                                               'curl'
          5        SEND_VAR                                                 !2
          6        DO_FCALL                                      0  $8      
          7        ASSIGN                                                   !3, $8
   34     8        INIT_FCALL                                               'regex_scrape'
          9        SEND_VAL                                                 '%2F%3Cspan+class%3D%5C%22h3+price-amount%5C%22%3E%28.%2A%29span%3E%2F'
         10        SEND_VAR                                                 !3
         11        DO_FCALL                                      0  $10     
         12        ASSIGN                                                   !4, $10
   37    13        INIT_FCALL                                               'var_dump'
         14        FETCH_DIM_R                                      ~12     !4, 0
         15        SEND_VAL                                                 ~12
         16        DO_ICALL                                                 
   38    17        INIT_FCALL                                               'array_sum'
         18        INIT_FCALL                                               'array_values'
         19        FETCH_DIM_R                                      ~14     !4, 0
         20        SEND_VAL                                                 ~14
         21        DO_ICALL                                         $15     
         22        SEND_VAR                                                 $15
         23        DO_ICALL                                         $16     
         24        CONCAT                                           ~17     'TOTAL%3A+', $16
         25        ECHO                                                     ~17
   40    26        INIT_FCALL                                               'array_merge'
         27        SEND_VAR                                                 !1
         28        FETCH_DIM_R                                      ~18     !4, 0
         29        SEND_VAL                                                 ~18
         30        DO_ICALL                                         $19     
         31        ASSIGN                                                   !1, $19
   41    32        INIT_FCALL                                               'strpos'
         33        SEND_VAR                                                 !3
         34        SEND_VAL                                                 '%3Cli+class%3D%22next+next_page%22%3E'
         35        DO_ICALL                                         $21     
         36      > JMPZ                                                     $21, ->47
   42    37    >   ASSIGN                                                   !0, <false>
   44    38        INIT_FCALL                                               'preg_match'
         39        SEND_VAL                                                 '%2F%3Cli+class%3D%22next+next_page%22%3E%3Ca+target%3D%22.%2A%22+rel%3D%22next%22+href%3D%22%28.%2A%29%22%3E%3Ci+class%3D%22icon+icon-caret-right%22%3E%2F'
         40        SEND_VAR                                                 !3
         41        SEND_REF                                                 !2
         42        DO_ICALL                                                 
   45    43        FETCH_DIM_R                                      ~24     !2, 1
         44        CONCAT                                           ~25     'https%3A%2F%2Fwww.airbnb.de', ~24
         45        ASSIGN                                                   !2, ~25
         46      > JMP                                                      ->48
   47    47    >   ASSIGN                                                   !0, <false>
   49    48    >   INIT_FCALL                                               'sleep'
         49        INIT_FCALL                                               'rand'
         50        SEND_VAL                                                 0
         51        SEND_VAL                                                 1
         52        DO_ICALL                                         $28     
         53        SEND_VAR                                                 $28
         54        DO_ICALL                                                 
   32    55    >   BOOL                                             ~30     !0
         56      > JMPNZ                                                    ~30, ->4
   52    57    > > RETURN                                                   1

Function curl:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eleo0
function name:  curl
number of ops:  34
compiled vars:  !0 = $url, !1 = $options, !2 = $ch, !3 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        FETCH_CONSTANT                                   ~4      'CURLOPT_RETURNTRANSFER'
          2        INIT_ARRAY                                       ~5      <true>, ~4
    5     3        FETCH_CONSTANT                                   ~6      'CURLOPT_FOLLOWLOCATION'
    4     4        ADD_ARRAY_ELEMENT                                ~5      <true>, ~6
    6     5        FETCH_CONSTANT                                   ~7      'CURLOPT_AUTOREFERER'
    4     6        ADD_ARRAY_ELEMENT                                ~5      <true>, ~7
    7     7        FETCH_CONSTANT                                   ~8      'CURLOPT_CONNECTTIMEOUT'
          8        ADD_ARRAY_ELEMENT                                ~5      120, ~8
    8     9        FETCH_CONSTANT                                   ~9      'CURLOPT_TIMEOUT'
         10        ADD_ARRAY_ELEMENT                                ~5      120, ~9
    9    11        FETCH_CONSTANT                                   ~10     'CURLOPT_MAXREDIRS'
         12        ADD_ARRAY_ELEMENT                                ~5      10, ~10
   10    13        FETCH_CONSTANT                                   ~11     'CURLOPT_USERAGENT'
         14        ADD_ARRAY_ELEMENT                                ~5      'Mozilla%2F5.0+%28X11%3B+U%3B+Linux+i686%3B+en-US%3B+rv%3A1.9.1a2pre%29+Gecko%2F2008073000+Shredder%2F3.0a2pre+ThunderBrowse%2F3.2.1.8', ~11
   11    15        FETCH_CONSTANT                                   ~12     'CURLOPT_URL'
         16        ADD_ARRAY_ELEMENT                                ~5      !0, ~12
    3    17        ASSIGN                                                   !1, ~5
   14    18        INIT_FCALL_BY_NAME                                       'curl_init'
         19        DO_FCALL                                      0  $14     
         20        ASSIGN                                                   !2, $14
   15    21        INIT_FCALL_BY_NAME                                       'curl_setopt_array'
         22        SEND_VAR_EX                                              !2
         23        SEND_VAR_EX                                              !1
         24        DO_FCALL                                      0          
   16    25        INIT_FCALL_BY_NAME                                       'curl_exec'
         26        SEND_VAR_EX                                              !2
         27        DO_FCALL                                      0  $17     
         28        ASSIGN                                                   !3, $17
   17    29        INIT_FCALL_BY_NAME                                       'curl_close'
         30        SEND_VAR_EX                                              !2
         31        DO_FCALL                                      0          
   18    32      > RETURN                                                   !3
   19    33*     > RETURN                                                   null

End of function curl

Function regex_scrape:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eleo0
function name:  regex_scrape
number of ops:  9
compiled vars:  !0 = $regex, !1 = $results_page, !2 = $match
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   23     2        INIT_FCALL                                               'preg_match_all'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        SEND_REF                                                 !2
          6        DO_ICALL                                                 
   24     7      > RETURN                                                   !2
   25     8*     > RETURN                                                   null

End of function regex_scrape

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.46 ms | 1407 KiB | 33 Q