The PHP Function Inet_Pon
The php function inet_pton converts an Internet network address from its text presentation form into its numeric binary form. The function takes as its argument a string representation of the IP address, and returns a buffer in network byte order that contains the numeric binary value of the address.
This function is used to create a human readable format for an IP address in a web application. The inet_pton() function is a very handy tool to have when developing websites that need to support both IPv4 and IPv6 addresses.
As you can see, this is a very simple function that converts an IP address from its string representation to its binary value. However, you should be aware that this function does not recognize netmask notation (e.g: “1.2.3.4/24” or “1:2::3:4/64”), and as such is not useful for database systems that require a specific datatype to store IPv6 addresses (e.g: MySQL or MariaDB).
The inet_pton() function is available on all platforms that have a functioning version of PHP. The function returns a 1 if the output is valid, and FALSE if an error occurred. When AF_INET is specified, the pAddrBuf parameter must point to a buffer large enough to hold an IN_ADDR structure. When AF_INET6 is specified, the pszAddrString parameter must point to a string representing an IPv6 address in dotted-octet notation (separated by colons). If either of these is not true, the function will return an extended error code as returned by WSAGetLastError.