3v4l.org

run code in 300+ PHP versions simultaneously
<?php $t=time(); //csv file write #$filename=date("Y-m-d",$t)."_work.csv"; $filename=$t."_data.csv"; $handle = fopen($filename, "w"); //Header for csv file $business = array("Business Name" , "Address1" ,"City","State","Zip code","Address2","Phone" , "Website" ,"Yelp Url"); fputcsv($handle,$business); $start=0; $csv_records = array(); for ($i = 0; $i <= 100; $i++) { $start=$i*10;//start count for pagination $args = $_SERVER['argv']; //$html = file_get_contents($args[1].'&start='.$start); $html = file_get_contents('http://www.yelp.com/search?find_desc=tasty+burger&find_loc=San+Francisco%2C+CA&start=10', 'w'); if(!empty($html)){ $pokemon_doc = new DOMDocument(); libxml_use_internal_errors(TRUE); //disable libxml errors $pokemon_doc->loadHTML($html); libxml_clear_errors(); //remove errors for yucky html $pokemon_xpath = new DOMXPath($pokemon_doc); //get all the span's with an class for getting Url $pokemon_row = $pokemon_xpath->query('/html/body//span[@class="indexed-biz-name"]/a'); $biz = array(); if($pokemon_row->length > 0){ foreach($pokemon_row as $row){ $biz['name'] = $row->nodeValue; $url1 = $row->getAttribute("href"); $biz['yelp_url'] = "http://www.yelp.com".$url1; $html1 = file_get_contents("http://www.yelp.com/".$url1); $pokemon_doc1 = new DOMDocument(); libxml_use_internal_errors(TRUE); $pokemon_doc1->loadHTML($html1); libxml_clear_errors(); //remove errors for yucky html $pokemon_xpath1 = new DOMXPath($pokemon_doc1); //get all the h2's with an id $pokemon_row1 = $pokemon_xpath1->query('/html/body//div[@class="mapbox-text"]/ul/li'); $biz['address'] = $pokemon_row1->item(0)->nodeValue; $biz['phone'] = $pokemon_row1->item(2)->nodeValue; if(preg_match('/Business website/',$pokemon_row1->item(3)->nodeValue)){ $biz['website']= $pokemon_row1->item(3)->nodeValue; } else{ $biz['website']= $pokemon_row1->item(4)->nodeValue; } //$biz['website'] ="http://".ltrim($bizwebsite,1); /* ############# Code to remove extra spaces and new line chars*/ $line_out_name = preg_replace('/[\n\r]+/', '', $biz['name']); $business_details_name = preg_replace('/[\s]+/', ' ', $line_out_name); $line_out_address = preg_replace('/[\r]+/', '', $biz['address']); $business_details_address = preg_replace('/[\s]+/', ' ', $line_out_address); $business_address=explode(",",$business_details_address); $add1=explode(" ",$business_address[0]); $add=$add1[0]." ".$add1[1]." ".$add1[2]; $add1=$add1[3]." ".$add1[4]; $add2=explode("b/t",$business_address[1]); $s=explode(" ",$add2[0]); $state=$s[1]; $zip=$s[2]; $lastadd="b/t".$add2[1]; $line_out_phone = preg_replace('/[\n\r]+/', '', $biz['phone']); $business_details_phone = preg_replace('/[\s]+/', ' ', $line_out_phone); $business_details_phone = preg_replace('/Phone number/','', $business_details_phone); $line_out_website = preg_replace('/[\n\r]+/', '', $biz['website']); $business_details_website = preg_replace('/Business website/','', $line_out_website); $business_details_website = preg_replace('/[\s]+/', '', $business_details_website); $business_details_website = "http://".$business_details_website; $business[0]= stripslashes(htmlspecialchars($business_details_name)); $business[1]= stripslashes($add); $business[2]= stripslashes($add1); $business[3]= stripslashes($state); $business[4]= stripslashes($zip); $business[5]= stripslashes($lastadd); $business[6]= stripslashes($business_details_phone); $business[7]= stripslashes($business_details_website); $business[8]= stripslashes($biz['yelp_url']); array_push($csv_records,($business[0]),$business[1],$business[2],$business[3],$business[4],$business[5],$business[6],$business[7],$business[8]); if (false !== $handle) { fputcsv($handle,$csv_records); } $csv_records = array(); } #foreach ends $pokemon_row } #if ends $pokemon_row->length > 0 }#if(!empty($html)) $business1 = ""; }#for ($i = 1; $i < 5; $i++) end ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 315
Branch analysis from position: 315
2 jumps found. (Code = 44) Position 1 = 317, Position 2 = 19
Branch analysis from position: 317
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 313
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 313
Branch analysis from position: 55
2 jumps found. (Code = 77) Position 1 = 56, Position 2 = 312
Branch analysis from position: 56
2 jumps found. (Code = 78) Position 1 = 57, Position 2 = 312
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 112, Position 2 = 119
Branch analysis from position: 112
1 jumps found. (Code = 42) Position 1 = 125
Branch analysis from position: 125
2 jumps found. (Code = 43) Position 1 = 306, Position 2 = 310
Branch analysis from position: 306
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
Branch analysis from position: 310
Branch analysis from position: 119
2 jumps found. (Code = 43) Position 1 = 306, Position 2 = 310
Branch analysis from position: 306
Branch analysis from position: 310
Branch analysis from position: 312
2 jumps found. (Code = 44) Position 1 = 317, Position 2 = 19
Branch analysis from position: 317
Branch analysis from position: 19
Branch analysis from position: 312
Branch analysis from position: 313
Branch analysis from position: 313
filename:       /in/Ot1mq
function name:  (null)
number of ops:  318
compiled vars:  !0 = $t, !1 = $filename, !2 = $handle, !3 = $business, !4 = $start, !5 = $csv_records, !6 = $i, !7 = $args, !8 = $html, !9 = $pokemon_doc, !10 = $pokemon_xpath, !11 = $pokemon_row, !12 = $biz, !13 = $row, !14 = $url1, !15 = $html1, !16 = $pokemon_doc1, !17 = $pokemon_xpath1, !18 = $pokemon_row1, !19 = $line_out_name, !20 = $business_details_name, !21 = $line_out_address, !22 = $business_details_address, !23 = $business_address, !24 = $add1, !25 = $add, !26 = $add2, !27 = $s, !28 = $state, !29 = $zip, !30 = $lastadd, !31 = $line_out_phone, !32 = $business_details_phone, !33 = $line_out_website, !34 = $business_details_website, !35 = $business1
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'time'
          1        DO_ICALL                                         $36     
          2        ASSIGN                                                   !0, $36
    5     3        CONCAT                                           ~38     !0, '_data.csv'
          4        ASSIGN                                                   !1, ~38
    7     5        INIT_FCALL                                               'fopen'
          6        SEND_VAR                                                 !1
          7        SEND_VAL                                                 'w'
          8        DO_ICALL                                         $40     
          9        ASSIGN                                                   !2, $40
    9    10        ASSIGN                                                   !3, <array>
   10    11        INIT_FCALL                                               'fputcsv'
         12        SEND_VAR                                                 !2
         13        SEND_VAR                                                 !3
         14        DO_ICALL                                                 
   12    15        ASSIGN                                                   !4, 0
   14    16        ASSIGN                                                   !5, <array>
   15    17        ASSIGN                                                   !6, 0
         18      > JMP                                                      ->315
   17    19    >   MUL                                              ~47     !6, 10
         20        ASSIGN                                                   !4, ~47
   18    21        FETCH_R                      global              ~49     '_SERVER'
         22        FETCH_DIM_R                                      ~50     ~49, 'argv'
         23        ASSIGN                                                   !7, ~50
   20    24        INIT_FCALL                                               'file_get_contents'
         25        SEND_VAL                                                 'http%3A%2F%2Fwww.yelp.com%2Fsearch%3Ffind_desc%3Dtasty%2Bburger%26find_loc%3DSan%2BFrancisco%252C%2BCA%26start%3D10'
         26        SEND_VAL                                                 'w'
         27        DO_ICALL                                         $52     
         28        ASSIGN                                                   !8, $52
   21    29        ISSET_ISEMPTY_CV                                 ~54     !8
         30        BOOL_NOT                                         ~55     ~54
         31      > JMPZ                                                     ~55, ->313
   22    32    >   NEW                                              $56     'DOMDocument'
         33        DO_FCALL                                      0          
         34        ASSIGN                                                   !9, $56
   23    35        INIT_FCALL                                               'libxml_use_internal_errors'
         36        SEND_VAL                                                 <true>
         37        DO_ICALL                                                 
   25    38        INIT_METHOD_CALL                                         !9, 'loadHTML'
         39        SEND_VAR_EX                                              !8
         40        DO_FCALL                                      0          
   26    41        INIT_FCALL                                               'libxml_clear_errors'
         42        DO_ICALL                                                 
   27    43        NEW                                              $62     'DOMXPath'
         44        SEND_VAR_EX                                              !9
         45        DO_FCALL                                      0          
         46        ASSIGN                                                   !10, $62
   30    47        INIT_METHOD_CALL                                         !10, 'query'
         48        SEND_VAL_EX                                              '%2Fhtml%2Fbody%2F%2Fspan%5B%40class%3D%22indexed-biz-name%22%5D%2Fa'
         49        DO_FCALL                                      0  $65     
         50        ASSIGN                                                   !11, $65
   32    51        ASSIGN                                                   !12, <array>
   34    52        FETCH_OBJ_R                                      ~68     !11, 'length'
         53        IS_SMALLER                                               0, ~68
         54      > JMPZ                                                     ~69, ->313
   35    55    > > FE_RESET_R                                       $70     !11, ->312
         56    > > FE_FETCH_R                                               $70, !13, ->312
   37    57    >   FETCH_OBJ_R                                      ~72     !13, 'nodeValue'
         58        ASSIGN_DIM                                               !12, 'name'
         59        OP_DATA                                                  ~72
   39    60        INIT_METHOD_CALL                                         !13, 'getAttribute'
         61        SEND_VAL_EX                                              'href'
         62        DO_FCALL                                      0  $73     
         63        ASSIGN                                                   !14, $73
   40    64        CONCAT                                           ~76     'http%3A%2F%2Fwww.yelp.com', !14
         65        ASSIGN_DIM                                               !12, 'yelp_url'
         66        OP_DATA                                                  ~76
   42    67        INIT_FCALL                                               'file_get_contents'
         68        CONCAT                                           ~77     'http%3A%2F%2Fwww.yelp.com%2F', !14
         69        SEND_VAL                                                 ~77
         70        DO_ICALL                                         $78     
         71        ASSIGN                                                   !15, $78
   44    72        NEW                                              $80     'DOMDocument'
         73        DO_FCALL                                      0          
         74        ASSIGN                                                   !16, $80
   45    75        INIT_FCALL                                               'libxml_use_internal_errors'
         76        SEND_VAL                                                 <true>
         77        DO_ICALL                                                 
   46    78        INIT_METHOD_CALL                                         !16, 'loadHTML'
         79        SEND_VAR_EX                                              !15
         80        DO_FCALL                                      0          
   47    81        INIT_FCALL                                               'libxml_clear_errors'
         82        DO_ICALL                                                 
   48    83        NEW                                              $86     'DOMXPath'
         84        SEND_VAR_EX                                              !16
         85        DO_FCALL                                      0          
         86        ASSIGN                                                   !17, $86
   51    87        INIT_METHOD_CALL                                         !17, 'query'
         88        SEND_VAL_EX                                              '%2Fhtml%2Fbody%2F%2Fdiv%5B%40class%3D%22mapbox-text%22%5D%2Ful%2Fli'
         89        DO_FCALL                                      0  $89     
         90        ASSIGN                                                   !18, $89
   52    91        INIT_METHOD_CALL                                         !18, 'item'
         92        SEND_VAL_EX                                              0
         93        DO_FCALL                                      0  $92     
         94        FETCH_OBJ_R                                      ~93     $92, 'nodeValue'
         95        ASSIGN_DIM                                               !12, 'address'
         96        OP_DATA                                                  ~93
   53    97        INIT_METHOD_CALL                                         !18, 'item'
         98        SEND_VAL_EX                                              2
         99        DO_FCALL                                      0  $95     
        100        FETCH_OBJ_R                                      ~96     $95, 'nodeValue'
        101        ASSIGN_DIM                                               !12, 'phone'
        102        OP_DATA                                                  ~96
   54   103        INIT_FCALL                                               'preg_match'
        104        SEND_VAL                                                 '%2FBusiness+website%2F'
        105        INIT_METHOD_CALL                                         !18, 'item'
        106        SEND_VAL_EX                                              3
        107        DO_FCALL                                      0  $97     
        108        FETCH_OBJ_R                                      ~98     $97, 'nodeValue'
        109        SEND_VAL                                                 ~98
        110        DO_ICALL                                         $99     
        111      > JMPZ                                                     $99, ->119
   55   112    >   INIT_METHOD_CALL                                         !18, 'item'
        113        SEND_VAL_EX                                              3
        114        DO_FCALL                                      0  $101    
        115        FETCH_OBJ_R                                      ~102    $101, 'nodeValue'
        116        ASSIGN_DIM                                               !12, 'website'
        117        OP_DATA                                                  ~102
        118      > JMP                                                      ->125
   58   119    >   INIT_METHOD_CALL                                         !18, 'item'
        120        SEND_VAL_EX                                              4
        121        DO_FCALL                                      0  $104    
        122        FETCH_OBJ_R                                      ~105    $104, 'nodeValue'
        123        ASSIGN_DIM                                               !12, 'website'
        124        OP_DATA                                                  ~105
   63   125    >   INIT_FCALL                                               'preg_replace'
        126        SEND_VAL                                                 '%2F%5B%5Cn%5Cr%5D%2B%2F'
        127        SEND_VAL                                                 ''
        128        FETCH_DIM_R                                      ~106    !12, 'name'
        129        SEND_VAL                                                 ~106
        130        DO_ICALL                                         $107    
        131        ASSIGN                                                   !19, $107
   64   132        INIT_FCALL                                               'preg_replace'
        133        SEND_VAL                                                 '%2F%5B%5Cs%5D%2B%2F'
        134        SEND_VAL                                                 '+'
        135        SEND_VAR                                                 !19
        136        DO_ICALL                                         $109    
        137        ASSIGN                                                   !20, $109
   67   138        INIT_FCALL                                               'preg_replace'
        139        SEND_VAL                                                 '%2F%5B%5Cr%5D%2B%2F'
        140        SEND_VAL                                                 ''
        141        FETCH_DIM_R                                      ~111    !12, 'address'
        142        SEND_VAL                                                 ~111
        143        DO_ICALL                                         $112    
        144        ASSIGN                                                   !21, $112
   68   145        INIT_FCALL                                               'preg_replace'
        146        SEND_VAL                                                 '%2F%5B%5Cs%5D%2B%2F'
        147        SEND_VAL                                                 '+'
        148        SEND_VAR                                                 !21
        149        DO_ICALL                                         $114    
        150        ASSIGN                                                   !22, $114
   70   151        INIT_FCALL                                               'explode'
        152        SEND_VAL                                                 '%2C'
        153        SEND_VAR                                                 !22
        154        DO_ICALL                                         $116    
        155        ASSIGN                                                   !23, $116
   72   156        INIT_FCALL                                               'explode'
        157        SEND_VAL                                                 '+'
        158        FETCH_DIM_R                                      ~118    !23, 0
        159        SEND_VAL                                                 ~118
        160        DO_ICALL                                         $119    
        161        ASSIGN                                                   !24, $119
   73   162        FETCH_DIM_R                                      ~121    !24, 0
        163        CONCAT                                           ~122    ~121, '+'
        164        FETCH_DIM_R                                      ~123    !24, 1
        165        CONCAT                                           ~124    ~122, ~123
        166        CONCAT                                           ~125    ~124, '+'
        167        FETCH_DIM_R                                      ~126    !24, 2
        168        CONCAT                                           ~127    ~125, ~126
        169        ASSIGN                                                   !25, ~127
   74   170        FETCH_DIM_R                                      ~129    !24, 3
        171        CONCAT                                           ~130    ~129, '+'
        172        FETCH_DIM_R                                      ~131    !24, 4
        173        CONCAT                                           ~132    ~130, ~131
        174        ASSIGN                                                   !24, ~132
   77   175        INIT_FCALL                                               'explode'
        176        SEND_VAL                                                 'b%2Ft'
        177        FETCH_DIM_R                                      ~134    !23, 1
        178        SEND_VAL                                                 ~134
        179        DO_ICALL                                         $135    
        180        ASSIGN                                                   !26, $135
   78   181        INIT_FCALL                                               'explode'
        182        SEND_VAL                                                 '+'
        183        FETCH_DIM_R                                      ~137    !26, 0
        184        SEND_VAL                                                 ~137
        185        DO_ICALL                                         $138    
        186        ASSIGN                                                   !27, $138
   79   187        FETCH_DIM_R                                      ~140    !27, 1
        188        ASSIGN                                                   !28, ~140
   80   189        FETCH_DIM_R                                      ~142    !27, 2
        190        ASSIGN                                                   !29, ~142
   82   191        FETCH_DIM_R                                      ~144    !26, 1
        192        CONCAT                                           ~145    'b%2Ft', ~144
        193        ASSIGN                                                   !30, ~145
   85   194        INIT_FCALL                                               'preg_replace'
        195        SEND_VAL                                                 '%2F%5B%5Cn%5Cr%5D%2B%2F'
        196        SEND_VAL                                                 ''
        197        FETCH_DIM_R                                      ~147    !12, 'phone'
        198        SEND_VAL                                                 ~147
        199        DO_ICALL                                         $148    
        200        ASSIGN                                                   !31, $148
   86   201        INIT_FCALL                                               'preg_replace'
        202        SEND_VAL                                                 '%2F%5B%5Cs%5D%2B%2F'
        203        SEND_VAL                                                 '+'
        204        SEND_VAR                                                 !31
        205        DO_ICALL                                         $150    
        206        ASSIGN                                                   !32, $150
   87   207        INIT_FCALL                                               'preg_replace'
        208        SEND_VAL                                                 '%2FPhone+number%2F'
        209        SEND_VAL                                                 ''
        210        SEND_VAR                                                 !32
        211        DO_ICALL                                         $152    
        212        ASSIGN                                                   !32, $152
   89   213        INIT_FCALL                                               'preg_replace'
        214        SEND_VAL                                                 '%2F%5B%5Cn%5Cr%5D%2B%2F'
        215        SEND_VAL                                                 ''
        216        FETCH_DIM_R                                      ~154    !12, 'website'
        217        SEND_VAL                                                 ~154
        218        DO_ICALL                                         $155    
        219        ASSIGN                                                   !33, $155
   90   220        INIT_FCALL                                               'preg_replace'
        221        SEND_VAL                                                 '%2FBusiness+website%2F'
        222        SEND_VAL                                                 ''
        223        SEND_VAR                                                 !33
        224        DO_ICALL                                         $157    
        225        ASSIGN                                                   !34, $157
   91   226        INIT_FCALL                                               'preg_replace'
        227        SEND_VAL                                                 '%2F%5B%5Cs%5D%2B%2F'
        228        SEND_VAL                                                 ''
        229        SEND_VAR                                                 !34
        230        DO_ICALL                                         $159    
        231        ASSIGN                                                   !34, $159
   92   232        CONCAT                                           ~161    'http%3A%2F%2F', !34
        233        ASSIGN                                                   !34, ~161
   94   234        INIT_FCALL                                               'stripslashes'
        235        INIT_FCALL                                               'htmlspecialchars'
        236        SEND_VAR                                                 !20
        237        DO_ICALL                                         $164    
        238        SEND_VAR                                                 $164
        239        DO_ICALL                                         $165    
        240        ASSIGN_DIM                                               !3, 0
        241        OP_DATA                                                  $165
   95   242        INIT_FCALL                                               'stripslashes'
        243        SEND_VAR                                                 !25
        244        DO_ICALL                                         $167    
        245        ASSIGN_DIM                                               !3, 1
        246        OP_DATA                                                  $167
   96   247        INIT_FCALL                                               'stripslashes'
        248        SEND_VAR                                                 !24
        249        DO_ICALL                                         $169    
        250        ASSIGN_DIM                                               !3, 2
        251        OP_DATA                                                  $169
   97   252        INIT_FCALL                                               'stripslashes'
        253        SEND_VAR                                                 !28
        254        DO_ICALL                                         $171    
        255        ASSIGN_DIM                                               !3, 3
        256        OP_DATA                                                  $171
   98   257        INIT_FCALL                                               'stripslashes'
        258        SEND_VAR                                                 !29
        259        DO_ICALL                                         $173    
        260        ASSIGN_DIM                                               !3, 4
        261        OP_DATA                                                  $173
   99   262        INIT_FCALL                                               'stripslashes'
        263        SEND_VAR                                                 !30
        264        DO_ICALL                                         $175    
        265        ASSIGN_DIM                                               !3, 5
        266        OP_DATA                                                  $175
  100   267        INIT_FCALL                                               'stripslashes'
        268        SEND_VAR                                                 !32
        269        DO_ICALL                                         $177    
        270        ASSIGN_DIM                                               !3, 6
        271        OP_DATA                                                  $177
  101   272        INIT_FCALL                                               'stripslashes'
        273        SEND_VAR                                                 !34
        274        DO_ICALL                                         $179    
        275        ASSIGN_DIM                                               !3, 7
        276        OP_DATA                                                  $179
  102   277        INIT_FCALL                                               'stripslashes'
        278        FETCH_DIM_R                                      ~181    !12, 'yelp_url'
        279        SEND_VAL                                                 ~181
        280        DO_ICALL                                         $182    
        281        ASSIGN_DIM                                               !3, 8
        282        OP_DATA                                                  $182
  103   283        INIT_FCALL                                               'array_push'
        284        SEND_REF                                                 !5
        285        FETCH_DIM_R                                      ~183    !3, 0
        286        SEND_VAL                                                 ~183
        287        FETCH_DIM_R                                      ~184    !3, 1
        288        SEND_VAL                                                 ~184
        289        FETCH_DIM_R                                      ~185    !3, 2
        290        SEND_VAL                                                 ~185
        291        FETCH_DIM_R                                      ~186    !3, 3
        292        SEND_VAL                                                 ~186
        293        FETCH_DIM_R                                      ~187    !3, 4
        294        SEND_VAL                                                 ~187
        295        FETCH_DIM_R                                      ~188    !3, 5
        296        SEND_VAL                                                 ~188
        297        FETCH_DIM_R                                      ~189    !3, 6
        298        SEND_VAL                                                 ~189
        299        FETCH_DIM_R                                      ~190    !3, 7
        300        SEND_VAL                                                 ~190
        301        FETCH_DIM_R                                      ~191    !3, 8
        302        SEND_VAL                                                 ~191
        303        DO_ICALL                                                 
  104   304        TYPE_CHECK                                  1018          !2
        305      > JMPZ                                                     ~193, ->310
  105   306    >   INIT_FCALL                                               'fputcsv'
        307        SEND_VAR                                                 !2
        308        SEND_VAR                                                 !5
        309        DO_ICALL                                                 
  107   310    >   ASSIGN                                                   !5, <array>
   35   311      > JMP                                                      ->56
        312    >   FE_FREE                                                  $70
  113   313    >   ASSIGN                                                   !35, ''
   15   314        PRE_INC                                                  !6
        315    >   IS_SMALLER_OR_EQUAL                                      !6, 100
        316      > JMPNZ                                                    ~198, ->19
  115   317    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.08 ms | 1424 KiB | 37 Q