PHP Function Reference

PHP getprotobyname() Function



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

Syntax

getprotobyname(protocol)

Parameters

protocol Required. Specify the protocol name.

Return Value

Returns the protocol number, or false on failure.

Example:

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

<?php
//finding the protocol number associated 
//with protocol name "tcp"
$protocol = "tcp";
$get_prot = getprotobyname($protocol);

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

The output of the above code will be:

Protocol #6

❮ PHP Network Reference

5