PDA

View Full Version : Breaking down a number


andyatkins46
03-26-2005, 08:34 PM
Hey!

Im looking for a way to break down an IP into 12 different numbers.

123.456.789.123

EG :

I want to know what the first number is, the second number, the third number and so on..

Also, if the IP doesnt have 3 numbers in each section I need to somehow reconise that...

Any ideas guys?

Andy

Fou-Lu
03-26-2005, 10:25 PM
$str = '127.0.0.1';

$parts = explode('.', $str);

print_r($parts);

ouput:

array(
[0] => 127
[1] => 0
[2] => 0
[3] => 1
)

So long as you keep it in string format, and even if in integer it will probably work, you can count this using strlen() function. Hope that helps. Btw, hopefully you are using this using real ip address, and the one here is just made up ;)

marek_mar
03-26-2005, 11:25 PM
So long as you keep it in string format, and even if in integer it will probably work, you can count this using strlen() function. Hope that helps. Btw, hopefully you are using this using real ip address, and the one here is just made up ;)
What do you mean made up? My server runs on that IP :p !

WarGiant
03-27-2005, 01:08 AM
127.0.0.1 is your own computer.

Fou-Lu
03-27-2005, 01:57 AM
Well, yes and no. 127.0.0.1 is your local host loopback address. Its not the same as your ip address.