这个问题怎么解决啊!

木目子 2003-12-28 03:54:31
这个问题怎么解决啊!谢谢
<?php
echo ip2long("211.154.21.191")."<br>";
echo (211*256*256*256+154*256*256+21*256+191)."<br>";
?>
-744876609
3550090687
...全文
29 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
木目子 2003-12-30
  • 打赏
  • 举报
回复
谢谢大家!
feel8 2003-12-28
  • 打赏
  • 举报
回复
ip2long
(PHP 4 )

ip2long -- Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address.
Description
int ip2long ( string ip_address)


The function ip2long() generates an IPv4 Internet network address from its Internet standard format (dotted string) representation. If ip_address is invalid than -1 is returned. Note that -1 does not evaluate as FALSE in PHP. 例子 1. ip2long() Example

<?php
$ip = gethostbyname("www.example.com");
$out = "The following URLs are equivalent:<br>\n";
$out .= "http://www.example.com/, http://".$ip."/, and http://".sprintf("%u",ip2long($ip))."/<br>\n";
echo $out;
?>




注: Because PHP's integer type is signed, and many IP addresses will result in negative integers, you need to use the "%u" formatter of sprintf() or printf() to get the string representation of the unsigned IP address.

This second example shows how to print a converted address with the printf() function : 例子 2. Displaying an IP address

<?php
$ip = gethostbyname("www.example.com");
$long = ip2long($ip);

if ($long === -1) {
print "Invalid IP, please try again";
} else {
print $ip . "\n"; // 192.0.34.166
print $long . "\n"; // -1073732954
printf("%u\n", ip2long($ip)); // 3221234342
}
?>




注: ip2long() will return -1 for the ip 255.255.255.255

phanx 2003-12-28
  • 打赏
  • 举报
回复
<?php
$ip = sprintf("%u", ip2long("211.154.21.191"))."<br>";
echo $ip;
echo (211*256*256*256+154*256*256+21*256+191)."<br>";
?>
ice_berg16 2003-12-28
  • 打赏
  • 举报
回复
没明白什么意思?

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧