Jump to content

PHP Sequance Generator help needed


amordeaa

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.