The Wayback Machine - https://web.archive.org/web/20230420163032/https://www.geeksforgeeks.org/php-getprotobynumber-function/
Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

PHP | getprotobynumber() Function

Improve Article
Save Article
Like Article
author
gekcho
proficient
149 published articles
Improve Article
Save Article
Like Article

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
  
// The getprotobynumber() function get protocol
// name associated with protocol number 
$protocolname = getprotobynumber(6);
  
// Display result
echo $protocolname;
?>

Output:

tcp

Program 2: This program checking for many protocol name.




<?php
  
// Store the protocol number in an array
$protocol_number  = array(6, 17, 20, 41);
  
foreach( $protocol_number as $number ){
      
    // The getprotobynumber() function get protocol
    // name associated with protocol 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

My Personal Notes arrow_drop_up
Last Updated : 30 Aug, 2019
Like Article
Save Article
Similar Reads
Related Tutorials