amordeaa Posted January 23, 2012 Share Posted January 23, 2012 Hello every one i am pretty new to PHP and here is what i am trying to accomplish: file1.csv has DECIMAL IP ADDRESSES range in the format of "202353920","202353951" "410129408","410129663" "410150912","410151167" "410178372","410178375" "410178560","410178815" I know how to read the numbers and place them in a text file by this code: All i am looking for is a code to generate that range between the first 2 fields for example 202353920 202353921 202353922 till 951 and then we move to the next line and do the same. I want the output to be to a file called range.txt. $row = 1; if (($handle = fopen("LONDON1.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); for ($c=0; $c < $num; $c++) { echo $data[$c]. "<br />\n"; } } this reads the all the fields .. but i dont know how to generate the sequance Part #2 is to get all these numbers and convert them from decimals to x.x.x.x hostnames ( that part i figured out already ) by the this code: function convert1($a){ $b=array(0,0,0,0); $c = 16777216.0; $a += 0.0; for ($i = 0; $i < 4; $i++) { $k = (int) ($a / $c); $a -= $c * $k; $b[$i]= $k; $c /=256.0; }; $d=join('.', $b); return($d); } But part #1 is where i am stuck ( to generate the numbers based on the given range. any help would be really appreciated. Quote Link to comment Share on other sites More sharing options...
litebearer Posted January 23, 2012 Share Posted January 23, 2012 hint range()... http://www.w3schools.com/php/func_array_range.asp Quote Link to comment Share on other sites More sharing options...
amordeaa Posted January 23, 2012 Author Share Posted January 23, 2012 thank you but the problem is how do i read the second field in a csv file and assign it to a variable. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted January 23, 2012 Share Posted January 23, 2012 Here's a hint for the second part: long2ip Quote Link to comment Share on other sites More sharing options...
amordeaa Posted January 23, 2012 Author Share Posted January 23, 2012 this has been solved thanks to litebearer Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.