PHP | getprotobyname() Function
The getprotobyname() function is an inbuilt function in PHP which returns the protocol number for a specified protocol name.
Syntax:
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”.
<?php // Use getprotobyname() function to // get the protocol number $protocolnum = getprotobyname("tcp"); // Display the result echo $protocolnum; ?> |
Output:
6
Program 2: This program checking the many protocols name.
<?php $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>"; } ?> |
Output:
6: tcp 17: udp 20: hmp 41: ipv6
Reference: https://www.php.net/manual/en/function.getprotobyname.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- PHP | pi( ) Function
- D3.js | d3.min() function
- D3.js | d3.max() function
- PHP | Ds\Set xor() Function
- PHP | Ds\Map xor() Function
- PHP | Ds\Map put() Function
- PHP | pow( ) Function
- PHP | each() Function
- PHP | Ds\Set add() Function
- p5.js | hex() function
- PHP | key() Function
- CSS | rgb() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



