PHP Function Reference

PHP getprotobynumber() Function



The PHP getprotobynumber() function returns the protocol name associated with the specified protocol number. The function returns false on failure.

Syntax

getprotobynumber(protocol)

Parameters

protocol Required. Specify the protocol number.

Return Value

Returns the protocol name as string, or false on failure.

Example:

The example below shows the usage of getprotobynumber() function.

<?php
//finding the protocol name associated 
//with protocol number 6
$protocol = 6;
$get_prot = getprotobynumber($protocol);

if ($get_prot === false) {
  echo 'Invalid Protocol number';
} else {
  echo 'Protocol name: ' . $get_prot;
}
?>

The output of the above code will be:

Protocol name: tcp

❮ PHP Network Reference