Saturday, November 22, 2025
HomeLanguagesPHP | inet_pton() Function

PHP | inet_pton() Function

The inet_pton() function is an inbuilt function in PHP which converts a readable format IP address into a packed 32bit IPv4 or 128bit IPv6 address.

Syntax:

string inet_pton( string $ip_address )

Parameters: This function accepts single parameter as mentioned above and described below:

  • $ip_address: It is required parameter. It specifies the readable IP address.

Return Value: This function returns a packed 32bit IPv4 or 128bit IPv6 address on success and FALSE on failure.

Note:

  • This function is available for PHP 5.1.0 and newer version.
  • Output of the following examples may differ in this page and actual output. So please see output screenshots.

Below programs illustrate the inet_pton() function in PHP:

Program 1:




<?php
  
// Use inet_pton() function on IP
// address and get result
$addr = inet_pton("127.0.1.1");
  
echo $addr;
  
?>


Output:

Program 2:




<?php
  
echo inet_pton("".gethostbyname("www.google.com"))."<br>";
echo inet_pton("".gethostbyname("www.youtube.com"))."<br>";
echo inet_pton("".gethostbyname("www.facebook.com"))."<br>";
echo inet_pton("".gethostbyname("www.geeksforgeeks.org"))."<br>";
echo inet_pton("".gethostbyname("php.net"))."<br>";
  
?>


Output:

Reference: https://www.php.net/manual/en/function.inet-pton.php

RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11931 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6848 POSTS0 COMMENTS