略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: getservbyname

2024-04-28

getservbyname

(PHP 4, PHP 5, PHP 7, PHP 8)

getservbyname获取互联网服务协议对应的端口

说明

getservbyname(string $service, string $protocol): int

getservbyname() 返回互联网服务 service 指定的协议 protocol 中对应的端口, 依据 /etc/services

参数

service

互联网服务名称的字符串。

protocol

protocol 既可以是 "tcp" 也可以是 "udp" (小写)。

返回值

返回端口号,如果 serviceprotocol 未找到返回 false

范例

示例 #1 getservbyname() 例子

<?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";
}
?>

参见

add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/function.getservbyname.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3