PHP | inet_ntop() Function
Last Updated :
05 Sep, 2019
The inet_ntop() function is an inbuilt function in PHP which converts a 32bit IPv4 or 128bit IPv6 address into a readable format.
Syntax:
string inet_ntop( string $ip_address )
Parameter: This function accepts one parameter as mentioned above and described below:
- $ip_address: It is required parameter. It specifies a 32bit IPv4 or 128bit IPv6 address.
Return Value: This function returns a string formatted human readable address on success or FALSE on failure.
Note: This function is available on PHP 5.1.0 and newer version.
Below programs illustrate the inet_ntop() function in PHP:
Program 1:
<?php
$addr = chr (127) . chr (0) . chr (1) . chr (1);
$exp = inet_ntop( $addr );
echo $exp ;
?>
|
Program 2: This program uses a string of size 4 of ascii characters directly in the parameter.
<?php
echo inet_ntop( "[][]" ) . "<br>" ;
echo inet_ntop( "4509" ) . "<br>" ;
echo inet_ntop( "*^b@" ) . "<br>" ;
echo inet_ntop( "hqp0" ) . "<br>" ;
echo inet_ntop( "2c#!" );
?>
|
Output:
91.93.91.93
52.53.48.57
42.94.98.64
104.113.112.48
50.99.35.33
Reference: https://www.php.net/manual/en/function.inet-ntop.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...