Jump to content

Recommended Posts

hi all

why this function return 0 and NOT 3573956936?

 

$ip = '213.6.65.72';
function ip2dec($ip) {
  $base=explode(".", $ip);
  $decimal=(double)$base[0]*16777216;
  $decimal+=$base[1]*65536;
  $decimal+=$base[2]*256;
  $decimal+=$base[3];
  if($decimal>2147483647) {
    $decimal-=4294967296;
  }
  return (int)$decimal;
}
echo ip2dec();

Link to comment
https://forums.phpfreaks.com/topic/165845-convert-ip-to-dottless-decimal/
Share on other sites

And you've got to pass the function a value when you call it. 0 in = 0 out.

how can i call my function to display the correct ip dottless?

 

dotless? str_replace(".","",$ip);

however, what they said was if you do function(); it's the same as function(0); which in turn, 0 "mathed" against anything will return 0 (which is why you get 0!)

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.