PHP IP string and Integer interchange

Source: Internet
Author: User

PHP has built-in functions ip2long can convert IP addresses to integer types.

Convert an integer to an IP address using LONG2IP

Example:

$ip = ' 58.6.207.207 '; $ip _int Ip2long ($ip); Echo $ip. " <br/> "; Echo $ip _int. " <br/> "; Echo Long2ip ($ip _int);

Conversion principle:
First, the first paragraph multiplied by 256 of the three square, the second segment multiplied by 256 squared, the third paragraph multiplied by 256, the last sum

$array [0]*256*256*256+ $array [1]*256*256+ $array [2]*256+ $array [3];

PHP IP string and Integer interchange

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.