PHP | getprotobynumber() Function
The getprotobynumber() function is an inbuilt function in PHP which returns the protocol name for a specified protocol number.
Syntax:
string getprotobynumber( int $protocol_number )
Parameters: This function accepts single parameter $protocol_number which is required. It specifies the protocol number, like 6 for tcp, 17 for udp etc.
Return Value: This function returns protocol name on success and FALSE on failure.
Note: This function is available for PHP 4.0.0 and newer version.
Below programs illustrate the getprotobynumber() function in PHP:
Program 1: This program uses protocol number for protocol name “tcp”.
<?php
$protocolname = getprotobynumber (6);
echo $protocolname ;
?>
|
Output:
tcp
Program 2: This program checking for many protocol name.
<?php
$protocol_number = array (6, 17, 20, 41);
foreach ( $protocol_number as $number ){
echo $number . ": " . getprotobynumber ( $number )
. "<br>" ;
}
?>
|
Output:
6: tcp
17: udp
20: hmp
41: ipv6
Reference: https://www.php.net/manual/en/function.getprotobynumber.php
Last Updated :
30 Aug, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...