Skip to content
Related Articles

Related Articles

PHP | getprotobyname() Function

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 03 Sep, 2019

The getprotobyname() function is an inbuilt function in PHP which returns the protocol number for a specified protocol name.


int getprotobyname( string $name )

Parameters: This function accepts single parameter $name which is required. It specifies the protocol name, like tcp, icmp, udp, ip etc.

Return Value: This function returns the protocol number on success and FALSE on failure.

Note: This function is available for PHP 4.0.0 and newer version.

Below programs illustrate the getprotobyname() function in PHP:

Program 1: This program gets the protocol number for protocol name “tcp”.

// Use getprotobyname() function to 
// get the protocol number
$protocolnum = getprotobyname("tcp");
// Display the result
echo $protocolnum;



Program 2: This program checking the many protocols name.

$protocols = array("tcp", "udp", "hmp", "ipv6");
foreach( $protocols as $protocol ){
    // Use getprotobyname() function to 
    // get the protocol number
    $protocol_name = getprotobyname($protocol);
    // Display the result
    echo $protocol_name . ": " . $protocol . "<br>";


6: tcp
17: udp
20: hmp
41: ipv6


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!