最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

探討PHP函數(shù)ip2long轉(zhuǎn)換IP時(shí)數(shù)值太大產(chǎn)生負(fù)數(shù)的解決方法

 更新時(shí)間:2013年06月06日 09:54:46   投稿:jingxian  
本篇文章是對(duì)PHP函數(shù)ip2long轉(zhuǎn)換IP時(shí)數(shù)值太大產(chǎn)生負(fù)數(shù)的解決方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下

【造成原因】:Because PHP's integer type is signed, and many IP addresses will result in negative integers.
【解決辦法】:其官方手冊(cè)中提到,可以“you need to use the "%u" formatter of sprintf() or printf() to get the string representation of the unsigned IP address”
即,printf( '%u', ip2long( 'IP地址' ) );
或者將其先轉(zhuǎn)換為二進(jìn)制然后在轉(zhuǎn)換為十進(jìn)制,bindec( decbin( ip2long( 'IP地址' ) ) );
【測(cè)試】
$strIp = '182.118.0.0';

echo ip2long($strIp); //此時(shí)輸出的-1233780736
echo '<br/>';
echo bindec( decbin( ip2long( $strIp ) ) ); // 輸出3061186560,與MySQL函數(shù)輸出一致~

【注】:
number bindec ( string $binary_string ); //二進(jìn)制轉(zhuǎn)換為十進(jìn)制
string decbin ( int $number ); //十進(jìn)制轉(zhuǎn)換為二進(jìn)制

以上這篇探討PHP函數(shù)ip2long轉(zhuǎn)換IP時(shí)數(shù)值太大產(chǎn)生負(fù)數(shù)的解決方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

盐源县| 收藏| 封开县| 卢龙县| 新巴尔虎右旗| 成都市| 澄城县| 桑日县| 巧家县| 沁水县| 张家口市| 灵璧县| 盘锦市| 霸州市| 赤峰市| 台东县| 汉阴县| 琼海市| 平度市| 武乡县| 铜梁县| 临朐县| 西和县| 宁南县| 金湖县| 马龙县| 宁国市| 丰台区| 屏东市| 阳西县| 西丰县| 乐陵市| 文安县| 黄石市| 元谋县| 灵宝市| 嘉义县| 晋江市| 凤冈县| 亚东县| 平定县|