English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The getservbyname() function retrieves the port corresponding to the internet service protocol.
int getservbyname ( string $service , string $protocol )
getservbyname() returns the port corresponding to the internet service protocol specified by service, based on /etc/services.
Returns the port number, if service or protocol is not found, returns FALSE.
Parameters | Description |
---|---|
service | String of the internet service name. |
protocol | protocol can be either "tcp" or "udp" (lowercase). |
Try the following example to get the port corresponding to the internet service protocol :
<?php $services = array('http', 'ftp', 'ssh', 'telnet', 'imap','smtp', 'nicname', 'gopher', 'finger', 'pop3', 'www'); foreach ($services as $service) { $port = getservbyname($service, 'tcp'); echo $service . ": " . $port . "<br />\n"; } ?>