Change language

PHP Getservbyname () Function

Syntax:
int getservbyname (string $service, string $protocol )
Parameters:This function takes two parameters as above and described below:
  • $protocol:required parameter. It specifies the name of the protocol, such as tcp, udp, etc. In string format.
  • $service:Required. It specifies the name of the Internet service, for example, the string format is http int.
Return Value:This function returns the port number on success, or False if the service or protocol is not found.Note.This function is available for PHP 4.0.0 and later.The following programs illustrate the getservbyname() function in PHP: Program 1:  
// Use the getservbyname() function to get
// port number associated with
// Internet service and protocol $portnum = getservbyname ( "http" , "tcp" );  
// Show result echo $portnum ;  
?>
Output:
80
Program 2:This program checks several services.  
// Create an array of services $services = array ( "ftp" , "ssh" , "telnet" , "http" , "https" );  
// startup loop for each service foreach ( $services as $index ) { // Use the getservbyname() function to get // port number associated with // Internet service and protocol echo getservbyname ( $index , "tcp" ) . ":" . $index . "
"
; }  
?>
Output:
21: ftp 22: ssh 23: telnet 80: http 443: https
Link: https://www.php.net/manual/en/function.getservbyname.php

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method