Tuesday, September 24, 2024
Google search engine
HomeLanguagesPHP | getprotobynumber() Function

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
  
// 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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments