Home php教程 php手册 php不常用ip转换函数与实例应用

php不常用ip转换函数与实例应用

Jun 02, 2016 am 09:14 AM

不看不知道一看吓一跳啊,在ip转换中在php中居然有函数,可以把ip转换整数,同样也要反过来转换,实例代码如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

$ip="127.0.0.1"//定义ip地址

$long=ip2long($ip);  //转换ip地址为整数

if($long==-1||$long===false)  //如果执行错误

{

    echo 'invalid ip, please try again'; //输出错误信息

}

else

{

    echo $ip  . "n"; //192.0.26.166

    echo "<br>";

    echo $long . "n"; // -1073732954

    printf("%un", ip2long($ip));  // 3221234342

}

//

$ip="127.0.0.1";           //定义ip地址

$long=ip2long($ip);           //转换ip地址为整数

if($long==-1||$long===false)         //如果执行错误

{

    echo &#39;invalid ip, please try again&#39;;        //输出错误信息

}

else

{

    echo $ip  . "n";           //192.0.26.166

    echo "<br>";

    echo $long . "n";           // -1073732954

    printf("%un", ip2long($ip));         // 3221234342

}

//再给一个常用字实例

$number="2130706433";        //定义数值

$ip=long2ip($number);        //转换为ip地址形式:127.0.0.1

echo $ip;

Copy after login


本文地址:

转载随意,但请附上文章地址:-)

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)