By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,403 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

Problem in understanding php code

P: 6
I am vaibhav here i am a .net developer. I need help if anybody can I am having one php code that I need to convert in asp.net. but I do not understand what actually they had done in php so if anybody can explain that what have they done then I can convert it.

Php code is as follows :

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $tt = "Corn Futures (CZ)";
  3. echo "<SPAN class='tt'>".$tt."</SPAN>";
  4. $rowspr = 0;
  5. $outmode = 0;
  6. $dataavl = 0;
  7. $hand = fopen("http://www.cbot.com/cbot/pub/page/0,3181,793,00.html",r);
  8.  
  9. while (!feof($hand)) {
  10.       $buffer = fgetss($hand, 4096,"<table><th><tr><td><br><ul><li>");
  11.  
  12.     if(strpos($buffer, "<table width='650' border='0' cellpadding='3' cellspacing='0' class='tableright'>")!==false){$outmode = 1;$dataavl = 1;}
  13.  
  14.     if(strpos($buffer, "<tr class='dataDetails")!==false){$rowspr = $rowspr + 1;}
  15.     if($rowspr == 4){$outmode = 0;echo "</table>"; $rowspr = $rowspr + 1;}
  16.  
  17.  
  18.     if($outmode == 1)
  19.     {
  20.     $buffer = str_replace("= Chart","",$buffer);
  21.     $buffer = str_replace("= Option","",$buffer);
  22.       echo $buffer;
  23.          if(strpos($buffer, "</table>")!==false){$outmode = 0;}
  24.     }
  25.     }
  26. fclose($hand);
  27. if($dataavl == 0){echo "<br><i>Data is currently not available.</i>";}
  28. ?>
  29.  
  30. &nbsp;<br>
  31. &nbsp;<br>
  32. &nbsp;<br>
  33.  
  34. <?php
  35. $tt = "Ethanol Futures (EZ)";
  36. echo "<SPAN class='tt'>".$tt."</SPAN>";
  37. $rowspr = 0;
  38. $outmode = 0;
  39. $dataavl = 0;
  40. $hand = fopen("http://www.cbot.com/cbot/pub/page/0,3181,1754,00.html",r);
  41.  
  42. while (!feof($hand)) {
  43.       $buffer = fgetss($hand, 4096,"<table><th><tr><td><br><ul><li>");
  44.  
  45.     if(strpos($buffer, "<table width='650' border='0' cellpadding='3' cellspacing='0' class='tableright'>")!==false){$outmode = 1;$dataavl = 1;}
  46.  
  47.     if(strpos($buffer, "<tr class='dataDetails")!==false){$rowspr = $rowspr + 1;}
  48.     if($rowspr == 4){$outmode = 0;echo "</table>"; $rowspr = $rowspr + 1;}
  49.  
  50.  
  51.     if($outmode == 1)
  52.     {
  53.     $buffer = str_replace("= Chart","",$buffer);
  54.     $buffer = str_replace("= Option","",$buffer);
  55.       echo $buffer;
  56.          if(strpos($buffer, "</table>")!==false){$outmode = 0;}
  57.     }
  58.     }
  59. fclose($hand);
  60. if($dataavl == 0){echo "<br><i>Data is currently not available.</i>";}
  61. ?>
  62.  
can anybody make me understand of this code.
Jan 8 '10 #1
Share this Question
Share on Google+
5 Replies


Dormilich
Expert Mod 5K+
P: 8,639
in short, they read a website and extract data from a HTML table.
Jan 8 '10 #2

P: 6
Thanks for reply but they read data from all HTML Tables or any specific table from that HTML Source.
Jan 9 '10 #3

Dormilich
Expert Mod 5K+
P: 8,639
any table that starts like defined in line #45
Jan 9 '10 #4

P: 6
You mean table which is defined only on line #45. no other tables have been read ?
Jan 11 '10 #5

Dormilich
Expert Mod 5K+
P: 8,639
basically, yes. Thatís what the code says.
Jan 11 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.