...

View Full Version : block the dot at the end



zodehala
03-11-2008, 02:16 PM
$ip = "10.0.8.101";
$oct = explode(".",$ip);

for ($i=0; $i<5; $i++){
echo decbin($oct[$i]).".";
}

how can i block the dot at the and of the output ? (i have marked it as red)


1010.0.1000.1100101.0.

flynch01
03-11-2008, 02:19 PM
for ($i=0; $i<5; $i++){
echo decbin($oct[$i]);
if ($i < 5) {
".";
}
}


Might have to change it to 4, i'm not sure. Probably a simpler method too.

zodehala
03-11-2008, 02:55 PM
for ($i=0; $i<5; $i++){
echo decbin($oct[$i]);
if ($i < 5) {
".";
}
}


Might have to change it to 4, i'm not sure. Probably a simpler method too.

lower than 4 is 3 . ther is no with 3 octed IP right ?

kbluhm
03-12-2008, 05:31 AM
The decimal is appearing at the end because you are concatenating a decimal within each iteration of the for-loop.

Here's a much more staight-forward method, no need for a for-loop:


// define the IP
$ip = '10.0.8.101';

// convert the decimal values to binary
$decbin = explode( '.', $ip );
$decbin = array_map( 'decbin', $decbin );
$decbin = implode( '.', $decbin );

// send it to the client
echo $decbin;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum